Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: hash dereferencing issue with perl 5.16.3

by aaron_baugher (Curate)
on May 03, 2015 at 03:28 UTC ( [id://1125482]=note: print w/replies, xml ) Need Help??


in reply to Re^2: hash dereferencing issue with perl 5.16.3
in thread hash dereferencing issue with perl 5.16.3

As far as identifying them goes, you could grep your files for ${%{$ . That sequence of characters isn't likely to show up anywhere else except in these constructs.

Automating a change would be more tricky, but could probably be done. Something like this which you could filter all problem files through:

#!/usr/bin/env perl use strict; use warnings; while(<DATA>){ print "before: $_";; s|\${%{\$(\w+)}}{'(\w+)'}|\$${1}->{'$2'}|g; print " after: $_";; } __DATA__ my $lValue = ${%{$lHashRef}}{'a'};

That might not work on all your variable names or if some are formatted a bit differently, but it could be a start.

Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.

Replies are listed 'Best First'.
Re^4: hash dereferencing issue with perl 5.16.3
by AnomalousMonk (Archbishop) on May 03, 2015 at 05:42 UTC
    That might not work on all your variable names or if some are formatted a bit differently ...

    In particular, note that it's possible to go a little nuts with whitespace and the Perl compiler still calmly accepts it. That, and the same basic extinct syntax also works with arrays and array references, which KANAKADANDI has never said are not present in the code.

    c:\@Work\Perl>perl -wMstrict -le "print qq{perl version $]}; ;; my @ra = qw(a b c d); my $ar = \@ra; print ${ ra }[2]; print ${ @ ra }[2]; print ${ $ ar }[2]; print ${ @ $ar }[2]; print ${ @ { $ ar } }[2]; ;; my %h = qw(a aye b bee c see); my $hr = \%h; print ${ h }{b}; print ${ % h }{b}; print ${ $ hr }{b}; print ${ % $hr }{b}; print ${ % { $ hr } }{b}; " perl version 5.008009 c c c c c bee bee bee bee bee

    Another point I would make is that a search for these extinct forms should be based on a rigorous definition of a Perl identifier (insofar as one can be defined in user code):
        my $identifier = qr{ \b [[:alpha:]_] \w* \b }xms;
    (or that's my first cut, anyway — but it doesn't cover "fully qualified" identifiers). See Variable names in perldata.

    I think the best automated search-and-replace is still going to need a final manual patching pass running with strictures enabled, which I sure hope KANAKADANDI is able to do!


    Give a man a fish:  <%-(-(-(-<

      Definitely. My goal with automation in a case like this would be to save as much typing as possible, but I'd still expect to have to test and review the edits manually. Also, I'd keep my regex fairly tight, even if that means it misses some due to unexpected formatting differences. Better to miss a few and have to edit those manually than to have it start replacing things I don't expect.

      Aaron B.
      Available for small or large Perl jobs and *nix system administration; see my home node.

      extinct forms

      Hmm, never tested for, never documented, actually goes against the documentation ... most mutations die off :)

        ... most mutations die off :)

        Yet sometimes there are surprising survivals among the forms we thought extinct. Like the coelacanth, they may be fascinating and delightful. Or they may be Godzilla.


        Give a man a fish:  <%-(-(-(-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-24 00:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found