Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Perl script on windows node

by kaka_2 (Sexton)
on Apr 03, 2012 at 11:53 UTC ( [id://963223]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl script on windows node
in thread Perl script on windows node

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: Perl script on windows node
by stevieb (Canon) on Apr 03, 2012 at 12:08 UTC

    say() is the only feature being used from 5.10, so all you need to do is replace all instances of 'say' with 'print'. To keep the output the same, add a newline character (\n) to the end of each quoted string you are printing out.

    EDIT: As pointed out by ww, I should have explicitly stated that along with replacing say with print, the 'use 5.10' line should be removed as well. Thanks!

      Perhaps stevieb assumed kaka2 would know to remove use 5.010 as well, but it's probably a good idea to explicitly include that instruction ... especially when saying "all you need to do is replace...'say' with 'print'."
      It seems working fine after using \\ in the path of file name as suggested by marto. Thank You all.
      Thanks Stevieb. I made the changes and compilation and execution was successfull but result is not satisfactory. It always says "File is not recent" where i see file was always got modified in last 120 seconds. Any thoughts?

        If you copy and paste this code as is and expect it to do what you want, it's not going to work. The variable $file needs to contain the path to a file for example:

        my $file = "C:\\stat.pl";

        With the value provided as an example the script will always pass through to the "File is not recent" message. You should alter the code to check for existing files. I'll leave that as an exercise for you.

        my $modified_within = 60 * 5; # 5 minutes

        Did you copy this line to the letter & number? - maybe you should adjust it to your needs.

        Cheers, Sören

        Well, if you're sure your looking at the right file, and that $modified_within is set to 60*2 or less, it may be a quirk on Windows. The code works here for me on my Ubuntu and FreeBSD machines.

        I don't run Perl on Windows, so hopefully someone else here can give the code a test, or perhaps spot something they may know doesn't work properly on the Win platform.

      Guys. i need further help. As a action i need to run a command. so what i did is added below in the BOLD.
      #use 5.010; use strict; my $modified_within = 60 * 2; # 2 minutes my $size_limit = 1024 * 1024 * 2; # 2 MB my $OPCMSG = "C:\Program Files\HP\HP BTO Software\bin\win64\OpC\opc +msg.exe"; my $file = "H:\\Program Data\\HP\\HP BTO Software\\shared\\tmp\\queues +\\MsgQueue"; if ([stat $file]->[9] > time - $modified_within) { if (-s $file > $size_limit) { # print "File is recent, and over size limit"; } else { print "File is recent, but not over size limit"; $OPCMSG a=OM9 o=failover s=normal mag_t="Hello!! I am fine, hope you a +re doing well"; } } else { print "File is not recent"; }
      But it return me error saying <c> Bareword found where operator expected at C:\Migration\failover.pl line 17, near "$OPCMSG a" (Missing operator before a?) syntax error at C:\Migration\failover.pl line 17, near "$OPCMSG a" Substitution replacement not terminated at C:\Migration\failover.pl line 17. How can i run this command through script?

        Please don't ignore the formatting guidelines, this obviously looked wrong when you previewed the post. Your code:

        #use 5.010; use strict; use strict; my $modified_within = 60 * 2; # 2 minutes my $size_limit = 1024 * 1024 * 2; # 2 MB my $OPCMSG = "C:\Program Files\HP\HP BTO Software\bin\win64\OpC\opcmsg +.exe"; my $file = "H:\\Program Data\\HP\\HP BTO Software\\shared\\tmp\\queues +\\MsgQueue"; if ([stat $file]->[9] > time - $modified_within){ if (-s $file > $size_limit) { print "File is recent, and over size limit"; } else { print "File is recent, but not over size limit"; $OPCMSG a=OM9 o=failover s=normal mag_t="Hello!! I am fine, ho +pe you are doing well"; } } else { print "File is not recent"; }

        I notice you ignored my previous advice to test that files exist, resulting in "File is not recent" being displayed for non existent files. Where did you copy and past this line from?

        $OPCMSG a=OM9 o=failover s=normal mag_t="Hello!! I am fine, hope you a +re doing well";

        And more to the point what do you expect it to do? A sensible guess would be that you expect to run opsmsg.exe with these arguments, but you've no idea how to do so and expect people to work through your messed up code and work out what you're trying to do. Don't make posts hard to read with regards formatting, and explain exactly what you're trying to achieve. Making people guess what you expect your hard to read code is doing is a bad strategy. Don't copy and paste code you found/were given online without any understanding of what it does.

        To achieve what you want see the example under system. If you're actually interested in learning Perl I suggest you invest the time reading:

        It does not like:
        $OPCMSG a=OM9 o=failover s=normal mag_t="Hello!! etc.";
        where did that come from?

Log In?
Username:
Password:

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

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

    No recent polls found