Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: reversed hash doesn't identify keys

by roboticus (Chancellor)
on Dec 11, 2012 at 22:33 UTC ( #1008415=note: print w/replies, xml ) Need Help??


in reply to reversed hash doesn't identify keys

holly71:

If you want to reverse the letter order in a word, you can do that by splitting the word into characters (via split), and then rejoin them in the correct order:

# Take a word my $word = "Constantinople"; # Split into letters: my @letters = split '', $word; # Reverse them my @srettel = reverse @letters; # Join back into a single word: my $drow = join('', @srettel);

Of course, you can combine it all into a single step:

my $drow = join('', reverse split //, "Constantinople");

Update: Or you could (as johngg pointed out) just use reverse, and it'll do the job without all the hoop-jumping-through-stuff.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: reversed hash doesn't identify keys
by johngg (Abbot) on Dec 11, 2012 at 23:22 UTC

    reverse works on scalar strings as well!

    $ perl -Mstrict -Mwarnings -E ' > my $word = q{Constantinople}; > my $drow = reverse $word; > say $drow;' elponitnatsnoC $

    I hope this is of interest.

    Cheers,

    JohnGG

      johngg:

      I've been writing perl for a good while now, and I'm frequently surprised at what I don't know.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

      Thanks very much! I had one too many "reverse"s in there and it was reversing the reversed letters back...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008415]
help
Chatterbox?
[oiskuu]: E.g. Re^3: Big thank you to the Perl community. is surely dry humor (not mine). Don't they teach humor in german schools!?
[LanX]: you don't see the whole picture
[LanX]: But reu germans have no humor, better to refrain from this site till the troll is gone...
[LanX]: true
[shmem]: I disagree

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-04-27 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (512 votes). Check out past polls.