Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Re: sorting a hash that's in another file

by snax (Hermit)
on Jul 23, 2003 at 21:06 UTC ( [id://277345]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: sorting a hash that's in another file
in thread sorting a hash that's in another file

Well, off the top of my head, I think this would work:
open SCRIPT, "script.pl" or die "you scurvy dog"; while (<SCRIPT>) { # Find the declaration next unless /\%some_hash/; $hash_declaration = $_; # Now pop out and do another while loop last; } while (<SCRIPT>) { # Keep appending until we reach a semi-colon $hash_declaration .= $_; last if /;/; } eval($hash_declaration);
But this assumes that you won't have a semi colon in the hash declaration in script.pl. There's a zillion ways to do the reading-in part, too, beyond just a smarter test for when you're done.

Replies are listed 'Best First'.
Re: sorting a hash that's in another file
by cLive ;-) (Prior) on Jul 23, 2003 at 22:03 UTC
    A very inefficient, but valid way of ensuring it works;
    use strict; use warnings; use Data::Dumper; open SCRIPT, "script.pl" or die "Can't open file: $!"; our $hash_declaration=''; our %some_hash; while (<SCRIPT>) { # Find the declaration next unless /\%some_hash/; $hash_declaration = $_; # Now pop out and do another while loop last; } while (<SCRIPT>) { # Keep appending until we reach a semi-colon $hash_declaration .= $_; eval $hash_declaration; last unless $@; } close(SCRIPT); print Data::Dumper->Dumper(\%some_hash);

    .02

    cLive ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-19 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found