Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: foreach (each character in string..)?

by robobunny (Friar)
on Jan 20, 2004 at 16:42 UTC ( [id://322629]=note: print w/replies, xml ) Need Help??


in reply to foreach (each character in string..)?

OK, since I was late with my legit response, here's a stupid way:
my @list; my $string = "hi there"; while($string) { push @list, chop($string); } foreach(reverse(@list)) { print "$_\n"; }

Replies are listed 'Best First'.
Re: Re: foreach (each character in string..)?
by boo_radley (Parson) on Jan 20, 2004 at 17:57 UTC

    make it smart-stupid with unshift.
    really not adding anything,
    boo

      To be honest, I'm amazed no one has bitched because it fails if you hand it the string '0', but thanks anyway :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://322629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-25 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found