Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: Bug in script, regex help req extreme urgent

by sid.verycool (Novice)
on Mar 09, 2013 at 18:37 UTC ( #1022602=note: print w/replies, xml ) Need Help??

in reply to Re: Bug in script, regex help req extreme urgent
in thread Bug in script, regex help req extreme urgent

1 confession, this code was written my 1 of my colleagues who left and i have to fix it. I'm trying to understand what this script exactly wants (specially the regex in my $string), so that any of my changes dont break original intent of script. Plz help me in understanding its objective and how can i transform it to read thru line by line, which is i think the easier way (atleast for a newbie like me) and yes if in the comment we change OLD to new it wud b gr8 because that is also wrong (although comments lie ;) shell#> file NEW OLD
#!/usr/bin/perl -w BEGIN {undef $/;} my $match = "module.*?$ARGV[2].*?([\\(;])"; my $filename = $ARGV[0]; open (INFILE, "<", $filename) or die "Failed to read file $filename +: $! \n"; $string = <INFILE>; close INFILE; $string =~ s/$match/module $ARGV[1]$1/sg; open OUTFILE, ">$ARGV[0]" || die "Failed to create $ARGV[0]\n"; print OUTFILE ($string); close OUTFILE;

Replies are listed 'Best First'.
Re^3: Bug in script, regex help req extreme urgent
by pvaldes (Chaplain) on Mar 09, 2013 at 21:53 UTC
    we change OLD to new it wud b gr8 because that is also wrong

    Can not understand this language, sorry. Maybe you need to provide a better example?.

Re^3: Bug in script, regex help req extreme urgent
by jaredor (Curate) on Mar 10, 2013 at 05:13 UTC

    If you want a likely story to explain things, then here's mine: Your colleague wanted to change an entire module definition file "in place" but didn't want to use a temporary file.

    On a Unix-type command line, you can do the same thing with

    perl -pie 's/\b module \s+ OLD \b/module NEW/xms;' file_name

    But back to your script. Your colleague didn't have to slurp the file into a single variable, he or she could have read the file into an array. The amount of memory taken up would have roughly been the same and the text processing could then have been done line-by-line.

    I don't know what relevant CPAN modules are out there to make in-place text file processing easier, but I'd bet there are some. For your emergency need right now the other excellent answers in this thread should give you enough to deliver something.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1022602]
[planetscape]: hello, Corion
[Corion]: Hi planetscape!
[stevieb]: Corion I like the groundbreaking ones (guitar players). I have the ability to pick up on sounds that are groundbreaking or specific to a person, thanks to my years of doing recording/mixing/ sampling (hip-hop mind you, but years of it...
[stevieb]: ...has honed in my skills of recognizing sound
[stevieb]: All of the early members are coming out of the woodwork today :) Hey, planetscape
[Corion]: This cover version had so much promise but the singing is underwhelming :-/
[stevieb]: erix Thanks! I dislike remakes of songs usually, but my favourite remix of guitar/weeps is Jeff Healey. I'll take a listen to yours
[planetscape]: hi stevieb!
[stonecolddevin]: also hi Corion
[Corion]: stevieb: Yeah, but I don't follow guitar players enough... I never got Prince and I don't think I could recognize his play style. I can recognize Santana and Nile Rodgers, but that's about it, and not really deep knowledge I think ;)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2017-06-22 21:28 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (531 votes). Check out past polls.