Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: string diff and compare

by raybies (Chaplain)
on May 04, 2012 at 15:36 UTC ( #968946=note: print w/replies, xml ) Need Help??

in reply to Re: string diff and compare
in thread string diff and compare

So I've gone through your example now. I understand everything in it, except...

 my ( $rold, $rnew ) = map scalar reverse, $old, $new;

What's up with the map scalar reverse syntax? What does the scalar do for example? I mean, I get that you're reversing two strings and putting them into two new strings, but I am really having difficulty parsing how Perl reads this to do what you've done here.

Anyone care to explain it, decompress it (for us mortals)?

Replies are listed 'Best First'.
Re^3: string diff and compare
by Anonymous Monk on May 04, 2012 at 15:54 UTC

    From perlod ...

    reverse LIST
    In list context, returns a list value consisting of the elements of LIST in the opposite order. In scalar context, concatenates the elements of LIST and returns a string value with all characters in the opposite order.

    And, read map chain as: map { scalar( reverse $_ ) } ( $old , $new ).

      "perlod"? Ha! :-) sounds like "perllord" was misspelled.
Re^3: string diff and compare
by jwkrahn (Monsignor) on May 04, 2012 at 21:27 UTC
    my ( $rold, $rnew ) = map scalar reverse, $old, $new;

    Is just a different way of saying:

    my $rold = reverse $old; my $rnew = reverse $new;

    You need to use scalar because reverse is in list context in the map expression.

      There are other ways of enforcing scalar context which are a lot more fun. :-)

      use 5.010; use strict; use warnings all => 'FATAL'; my ( $old, $new ) = qw( old new ); my ( $rold, $rnew ) = map~~reverse, $old, $new; say for "$old => $rold", "$new => $rnew";
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://968946]
[Eily]: you mean a dll where the SW was written in perl? That sounds unlikely
[muthusathish]: please help me regarding this
[hippo]: Easier just to go and look at the source, no?
[Eily]: mostly because perl isn't compiled in the usual sense of the meaning, you can't execute the opcodes directly, you need the perl engine
[muthusathish]: i dont have the environment too, but i need to get the logics so that i can re-wite
[Eily]: what makes you think your dll is "perl based" ?
[muthusathish]: i dont have source code too
[muthusathish]: it is used in VB 6 appln, while debugging is getting error
[hippo]: Somebody has. Ask the author.
[Eily]: muthusathish ok, the fact that you can't tell what perl has to do with it proves it: this is not perl

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2018-02-23 09:14 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (301 votes). Check out past polls.