Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

My script is working fine on linux but it's not working on the Windows

by galacticos (Initiate)
on Nov 17, 2011 at 09:48 UTC ( #938567=perlquestion: print w/ replies, xml ) Need Help??
galacticos has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/perl $y_date= `date --date="yesterday"`; $y_date =~ s/IST//g; $y_date =~ m/(\d+)$/; $year= $1; print $year; $y_date =~ m/^(\w+\s\w+\s\w+)/; #print $y_date; $day=$1; print $day; open(FH,"C:\\arerror.log") or die "Unable to open logfile:$!\n"; open(OUT,">C:\\output.log") or die "Unable to open output file:$!\n"; @fileco=<FH>; @grepLogs = grep(/$day(.*)$year/,@fileco ); print OUT @grepLogs;

Actuall in windows this programme is working fine But at the same time When I am trying this programme in windows it's not working and one more thing when i exectue my perl script in windows it's got stuck in cmd but after that when i prees enetr two or three time it will throw thius error " the system cannot" only these three word please check this if it's possible ...

Thanks and regards

Galacticos

Comment on My script is working fine on linux but it's not working on the Windows
Download Code
Re: My script is working fine on linux but it's not working on the Windows
by marto (Chancellor) on Nov 17, 2011 at 09:54 UTC

      Actuall in windows this programme is working fine But at the same time When I am trying this programme in windows it's not working and one more thing when i exectue my perl script in windows it's got stuck in cmd but after that when i prees enetr two or three time it will throw thius error " the system cannot" only these three word please check this if it's possible ... Thanks and regards Galacticos

      #!/usr/bin/perl use strict; use warnings; $y_date= `date --date="yesterday"`; $y_date =~ s/IST//g; $y_date =~ m/(\d+)$/; $year= $1; print $year; $y_date =~ m/^(\w+\s\w+\s\w+)/; #print $y_date; $day=$1; print $day; open(FH,"C:\\arerror.log") or die "Unable to open logfile:$!\n"; open(OUT,">C:\\output.log") or die "Unable to open output file:$!\n"; @fileco=<FH>; @grepLogs = grep(/$day(.*)$year/,@fileco ); print OUT @grepLogs;

        Instead of relying on an external date program, consider looking at localtime.

        "Actuall in windows this programme is working fine But at the same time When I am trying this programme in windows it's not working and one more thing when i exectue my perl script in windows it's got stuck in cmd but after that when i prees enetr two or three time it will throw thius error " the system cannot" only these three word please check this if it's possible ..."

        So it's working fine, apart from the fact that it doesn't work?

        $y_date= `date --date="yesterday"`;

        had you actually run this from the command prompt you'd notice that you're being prompted for user input, hence pressing enter multiple times provides the (invalid) input. The error you get isn't from your perl code, its because you don't understand what date does. As Corion suggested, don't reply on an external program (albeit the wrong program, which you don't seem to understand how to use) to get yesterdays date.

        I noticed you've added use strict; use warnings now your code won't even get to the line which causes the problem. Did you even try running this?

      I have used use strict and use warnings; now it's showing me this things Global symbol "$y_date" requires explicit package name at logscript.pl line 4. Global symbol "$y_date" requires explicit package name at logscript.pl line 6. Global symbol "$y_date" requires explicit package name at logscript.pl line 7. Global symbol "$y_date" requires explicit package name at logscript.pl line 8. Global symbol "$year" requires explicit package name at logscript.pl line 9. Global symbol "$y_date" requires explicit package name at logscript.pl line 11. Global symbol "$y_date" requires explicit package name at logscript.pl line 12. Global symbol "$day" requires explicit package name at logscript.pl line 14. Global symbol "@fileco" requires explicit package name at logscript.pl line 19. Global symbol "@grepLogs" requires explicit package name at logscript.pl line 20. Global symbol "$day" requires explicit package name at logscript.pl line 20. Global symbol "$year" requires explicit package name at logscript.pl line 20. Global symbol "@fileco" requires explicit package name at logscript.pl line 20. Global symbol "@grepLogs" requires explicit package name at logscript.pl line 22. logscript.pl had compilation errors.

        Wonderful, now all you have to do is actually read and understand the links I gave you to find out what this means, and how to fix it.

      I have used use strict and use warnings; now it's showing me this things

      Global symbol "$y_date" requires explicit package name at logscript.pl line 4. Global symbol "$y_date" requires explicit package name at logscript.pl line 6. Global symbol "$y_date" requires explicit package name at logscript.pl line 7. Global symbol "$y_date" requires explicit package name at logscript.pl line 8. Global symbol "$year" requires explicit package name at logscript.pl line 9. Global symbol "$y_date" requires explicit package name at logscript.pl line 11. Global symbol "$y_date" requires explicit package name at logscript.pl line 12. Global symbol "$day" requires explicit package name at logscript.pl line 14. Global symbol "@fileco" requires explicit package name at logscript.pl line 19. Global symbol "@grepLogs" requires explicit package name at logscript.pl line 20. Global symbol "$day" requires explicit package name at logscript.pl line 20. Global symbol "$year" requires explicit package name at logscript.pl line 20. Global symbol "@fileco" requires explicit package name at logscript.pl line 20. Global symbol "@grepLogs" requires explicit package name at logscript.pl line 22. logscript.pl had compilation errors.

Re: My script is working fine on linux but it's not working on the Windows
by sundialsvc4 (Monsignor) on Nov 17, 2011 at 13:51 UTC

    Pardon me... but I don’t think that you are listening to us all.

    • First and foremost, use <code> tags to make your code readable.
    • Second, you can expect us to willingly try to assist you, but we can’t do your job for you.   So, please don’t merely “make a change to the code and ask us to debug it for you.”   (Perhaps you can obtain this kind of tutoring from a colleague?)

    Am I saying these things merely because “I am pissed-off at you?”   Frankly, no.   But there is a right way to go about availing yourself effectively of the PerlMonks resource, and it makes a big difference to your success.   “You want help.   We want to help you.   Learn How.

Re: My script is working fine on linux but it's not working on the Windows
by Anonymous Monk on Nov 18, 2011 at 00:01 UTC

    Hi,

    A little hint - look up 'my' in the perl documentation.

    J.C.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://938567]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-08-28 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (254 votes), past polls