CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
characters?

 



perlkid
stranger

Feb 17, 2000, 3:23 AM

Post #1 of 3 (660 views)
characters? Can't Post

 Is there any way to read the first two character (numbers) of a key in a hash so that I can use them to open a file based on what they are?

ex:

$scalar = first2char ($hash{'key'});
open (FILE, "$scalar.txt");


Thanks,
perlkid

[This message has been edited by perlkid (edited 02-17-2000).]


japhy
Enthusiast

Feb 17, 2000, 4:09 AM

Post #2 of 3 (660 views)
Re: characters? [In reply to] Can't Post

Embrace the substr() function:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$first_two = substr $string, 0, 2;
$second_two = substr $string, 2, 2;
$last_three = substr $string, -3;
$second_to_last = substr $string, -2, 1;
</pre><HR></BLOCKQUOTE>

PerlArchive has the perl docs if you don't, so read up on substr().


perlkid
stranger

Feb 17, 2000, 12:36 PM

Post #3 of 3 (660 views)
Re: characters? [In reply to] Can't Post

 
Whoo Hoo,

I cna't believe that worked! It worked perfectly. Thank you soo much,

perlkid

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives