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

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: delete a line from a file
by toolic (Bishop) on Jan 28, 2010 at 16:09 UTC
Re: delete a line from a file
by umasuresh (Hermit) on Jan 28, 2010 at 15:59 UTC
    Please enclose your code with code tags. Otherwise it is very hard to read the code!
Re: delete a line from a file
by Utilitarian (Vicar) on Jan 28, 2010 at 16:24 UTC
    +1 add code tags your code should look like
    if ( -f $working_file ) { open WORKINGFILE, "<$working_file" or die $!; while (<WORKINGFILE>) { $line = $_; #@storelist - I am getting this thru a sql statement foreach $temp (@storelist) { chomp $temp; ($x,$store,$distri,$end_date)=split(';',$temp); chomp $store,$distri,$end_date; # print LOG "The store in the lookup is $store and the distributo +r is $distri\n"; if ( "$store" ne "" && "$end_date" eq "" ) { if ( substr($_,0,4) =~ "$store" ) { open NEWFILE,">>$temp_dir$next_file" or warn $!; print NEWFILE $_; # delete $_ from $working_file ?????????? HOW ???? } } }
    However you should have noticed on the preview page that it didn't, weren't you curious?

    You need to write the lines you wish to keep to a temporary file and rename it on completion or create an array tied to the file.

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

      Thanks Utiltarian. This is the first time I have asked a question. to further clarify what I am asking, the original $working_file looks like this: 1001201001030000000000745706511000001785565602 0000000 00000008523978089697855656020003 1002201001030000000000415480038500001785565602 0000000 00000008523978089697855656020003 1003201001030000000000415480038600002785565602 0000000 00000008523978089697855656020003 1004201001030000000007897850196300002785565602 0000000 00000008523978089697855656020003 1005201001030000000000415480268500001785565602 0000000 00000008523978089697855656020003 1006201001030000000000415486051000001785565602 0000000 00000008523978089697855656020003 1007201001030000000000745700340000002785565602 0000000 00000008523978089697855656020003 1008201001030000000000745700331000001785565602 0000000 00000008523978089697855656020003 1009201001030000000000725541110000001785565602 0000000 00000008523978089697855656020003 1010201001030000000000745706510900001785565602 0000000 00000008523978089697855656020003 1011201001030000000000745700240000001785565602 0000000 00000008523978089697855656020003

      and the first 4 chars is the store number. If store 1002, 1009 & 1010 are in @store list the $working_file should looks like this:

      1001201001030000000000745706511000001785565602 0000000 00000008523978089697855656020003 1003201001030000000000415480038600002785565602 0000000 00000008523978089697855656020003 1004201001030000000007897850196300002785565602 0000000 00000008523978089697855656020003 1005201001030000000000415480268500001785565602 0000000 00000008523978089697855656020003 1006201001030000000000415486051000001785565602 0000000 00000008523978089697855656020003 1007201001030000000000745700340000002785565602 0000000 00000008523978089697855656020003 1008201001030000000000745700331000001785565602 0000000 00000008523978089697855656020003 1011201001030000000000745700240000001785565602 0000000 00000008523978089697855656020003

        So you get the first four characters from your record substr and check if it is in the list, one way to do this would be
        map {$valid = 1 if $store eq $_;}@store;)
        I'm sure there is a better idiom, but I can't think of it @ the moment

        print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
Re: delete a line from a file
by snape (Pilgrim) on Jan 28, 2010 at 16:20 UTC
    while ($temp = <$INPUT>) { if ($temp !~ /<pattern>/) { chomp; my @line = split(';', $temp); } }
Re: delete a line from a file
by molecules (Monk) on Jan 28, 2010 at 16:54 UTC