Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    31
    Thanks
    25
    Thanked 0 Times in 0 Posts

    stuck on print function again

    Hi, I’m stuck on print function again.
    I made a script, it finds a string then I want to print everything from the string to the end of the file.
    It does all I need but the “print” part. Here is the script, please help.
    Thanks vl123456
    #!/usr/bin/perl
    use strict ;
    use warnings ;
    use diagnostics ;

    use diagnostics ;
    my @array ;
    my $tmp ;
    my $array ;


    my $pasttime ;
    my $weekago = time - 24 * 60 * 60 * 7;
    my ($year, $month, $day) = (localtime($weekago))[5,4,3];
    my $date = sprintf ("%04d %02d %02d", $year+1900, $month+1, $day);

    $pasttime = $date ;


    my $inptf ;
    my $outpf ;

    $inptf = 'C:\\PERL_TEST\\TimeS\\timelog.txt ' ;
    $outpf = 'C:\\PERL_TEST\TimeS\\timelog02.txt' ;
    open (DIN, "<$inptf") or die "Can't open $inptf : $!" ;
    open (DOUT, ">$outpf") or die "Can't open $outpf : $!" ;

    while (<DIN> )
    {


    if ($_ =~/$pasttime/gi)
    {
    print DOUT "$_ ";
    print DOUT ;

    print "$_\n" ;
    print "1Week ago Date was $pasttime\n" ;
    }
    else {
    print "NOT FOUND THE DATE\n" ;

    }
    }

    close DIN ;
    close DOUT ;

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    You need to use the range operator.

    Code:
    while(<DIN>) {
        if ( /$pasttime/ .. eof ) {
            print;
        }
    }

  • Users who have thanked FishMonger for this post:

    vl123456 (06-25-2011)

  • #3
    New Coder
    Join Date
    Mar 2011
    Posts
    31
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Thank you FishMonger! It works perfectly, does exactly what I want.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •