Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

insertion of string one time infront of a larger string

by drock (Beadle)
on Jun 18, 2004 at 16:52 UTC ( #367995=perlquestion: print w/replies, xml ) Need Help??

drock has asked for the wisdom of the Perl Monks concerning the following question:

my @ejectapes = qw(/usr/local/bin/perld/lvimgGH_ms0_tapes.orig); #($^I, @ARGV) = ('.bak', @ejectapes); open (FILE, "< @ejectapes") or die "cannot open @ejectapes: $!"; while (<FILE>) { chomp; print "$_ " if 1 .. 40; } #s/(^E+)/eject\t0,0,0 \t$1/ close FILE; print "\n";
The file has 41 lines with Exxxxx strings in it. My goal is to open this file while taking the first 40 lines ( as you showed me earlier) which then I will insert the eject 0,0,0 string at the very beginning one time. The regular expression as above is commented out and has worked for me in the past but it places an eject in from of every E string. Here is a picture of what I need. eject 0,0,0 Exxxxx Exxxxx Exxxxx Exxxxx Exxxxx .....( Exxx x40) and currently it looks like this which is NOT what I want eject 0,0,0 Exxxx eject 0,0,0 Exxxxx eject 0,0,0 Exxxx (x40) thanks, derek

Replies are listed 'Best First'.
Re: insertion of string one time infront of a larger string
by Roy Johnson (Monsignor) on Jun 18, 2004 at 17:06 UTC
    How about just putting a print statement in front of the while loop?
    print "eject\t0,0,0 \t"; while (<FILE>) {

    We're not really tightening our belts, it just feels that way because we're getting fatter.
Re: insertion of string one time infront of a larger string
by pbeckingham (Parson) on Jun 18, 2004 at 18:12 UTC

    if (open FILE, '< /usr/local/bin/perld/lvimgGH_ms0_tapes.orig') print "eject 0,0,0\n"; print for <FILE>; close FILE; }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://367995]
Approved by pbeckingham
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2023-09-25 15:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found