Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: •Re: mmv-like hack in perl?

by mpd (Monk)
on Apr 14, 2003 at 05:20 UTC ( [id://250225]=note: print w/replies, xml ) Need Help??


in reply to •Re: mmv-like hack in perl?
in thread mmv-like hack in perl?

Thank you for your help. I think I'm still having a problem with the line:

s/$pattern/qq{$replace}/eeg;

Here's the snippet that's failing:

# get strings from GUI. my $old = my $new = $_->children->get; # get old filename my $pattern = $form->{'entry2'}->get_text(); # e.g. $pattern == "^(\d{2})\. (.*)$" after this my $replace = $form->{'entry1'}->get_text(); # e.g. $replace == "two-$2, one-$1" after this # is the following match necessary? $1, etc # need to be assigned somehow... if($old =~ /$pattern/) { $new =~ s/$pattern/qq{$replace}/eeg; print STDERR $old." => ".$new."\n"; }

After the $new =~ line, $new is empty, every time. Am I missing something? Thanks again

Replies are listed 'Best First'.
•Re: Re: •Re: mmv-like hack in perl?
by merlyn (Sage) on Apr 14, 2003 at 10:13 UTC
    $new = $old; $new =~ s/$pattern/qq{$replace}/eeg;
    But you're scaring me here. I said that the string had to be from a trusted source. As soon as you start talking "GUI", that makes me think that the user-ID of the person typing the string is not necessarily the user-ID of the person running the code.

    Let me reemphasize. Using this code as-is will allow any arbitrary Perl code to be executed, including shelling out to execute arbitrary system commands. Clear? It's not just about mangling a string. You must either trust the invoker, or not use this code.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Perfectly clear. That's what I want to do, because this is just a toy for me to play with. I don't plan on releasing this piece of my junky code. I will likely end up parsing it myself as Aristotle suggests below. If something clever comes out, I will post that bit of code, of course.

      Thanks again.

Log In?
Username:
Password:

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

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

    No recent polls found