Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: use string as a piece of code

by FunkyMonk (Chancellor)
on Jul 30, 2010 at 16:45 UTC ( [id://852116]=note: print w/replies, xml ) Need Help??


in reply to use string as a piece of code

eval.

my $str = '1..3,10..14'; do_something($_) for eval $str;

Just be very sure that you trust whoever created the file you're reading from. What happens if it contains "system qw{rm -rf /}" (or the equivalent on your OS)?

update: Added code

Replies are listed 'Best First'.
Re^2: use string as a piece of code
by daverave (Scribe) on Jul 30, 2010 at 16:49 UTC
    Thanks!

    A followup: my ranges are quite large (~500k numbers, usually in one or two blocks only, i.e. something like 1..20000,700000..1000000).

    What is the efficient way to simply print them out to a file?

    Maybe  for $i (1..20000,700000..1000000) {print "$i "}? I'm not sure if an array is actually created here... if it is, maybe it's not a good idea.

Log In?
Username:
Password:

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

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

    No recent polls found