Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Not A Rockstar File Manipulator Today

by koolgirl (Hermit)
on Nov 14, 2008 at 23:33 UTC ( [id://723748]=note: print w/replies, xml ) Need Help??


in reply to Not A Rockstar File Manipulator Today

OK, when asked for input, I give the path to the input and output file which happens to be (E:/passwords/moonlight_mile) and (E:/passwords/jumpin_jack_flash) then the pattern I give is "line", and the replacement I give is "foo". Both files merely contain these four lines.
line1 line2 line3 line4
I only get an empty output file and an unchanged input file afterwards. Please anyone? Everyone keeps telling me it works but it doesn't....should I just put the straight jacket on now or....

UPDATE: Oh and the capital S on my s/pat/rep line is a typo, not actually in my code :) sorry, that's not the mystery.

Replies are listed 'Best First'.
Re^2: Not A Rockstar File Manipulator Today
by jethro (Monsignor) on Nov 15, 2008 at 00:12 UTC

    S a typo? Does that mean you didn't copy and paste the code but wrote it down a second time? In that case are you sure both programs are identical now?

    One thing you might do now is debugging. I.e. put print statements into you code to check the changes in $_. Your loop might look like this:

    print "REPLACE <$pattern> with <$replacement>\n"; while (<IN>) { # print "<$_>\n"; S/$pattern/$replacement/g; print "AFTER <$_>\n"; print OUT $_; } # end while

    Or you might use perls debugger where you can execute a line, look at any and all variables you like, execute the next line, look at .... Just call your script with perl -d and use 's' or 'n' to single step and 'p $_' to see the contents of variable $_, for example. 'h' gives you a help page. It is really simple and easy to work with, read 'man perldebug if you want to know more'

      Inline debugging is really, really helpful in cases like this. You might also want to change the

      print OUT $_;
      to
      print ;
      to print your lines on the screen.

      And for a sanity check, you might put something like:

      print "\$in_file: $in_file \n"; print "\$out_file: $out_file \n"; print "\$pattern : $pattern\n"; print "\$replacement: $replacement\n";
      before your open commands. Just to make sure you're opening the file(s) you think you're opening.

Log In?
Username:
Password:

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

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

    No recent polls found