Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Okay I have cleaned it up a little bit

by Kevin_Raymer
on Feb 15, 2007 at 15:58 UTC ( #600223=perlquestion: print w/ replies, xml ) Need Help??
Kevin_Raymer has asked for the wisdom of the Perl Monks concerning the following question:

I have taken your computer feedback to heart and cleaned up my code a little bit - I think this a lot more perl like and pretty technical.

#!/usr/bin/perl -w use strict; system "netbackup/bin/admincmd/bpdbjobs -report -all_columns\n"; mail "xxxxxx@xxxxx.com

but still I get:

Bareword "com" not allowed while "strict subs" in use at ./nb.pl line +7.<br> Unquoted string "com" may clash with future reserved word at ./nb.pl l +ine 7.<br> Execution of ./nb.pl aborted due to compilation errors. <br>
I had a real email address in there of course. This is really a challange it reminds me of the days of hacking AOL!
KR

Comment on Okay I have cleaned it up a little bit
Select or Download Code
Re: Okay I have cleaned it up a little bit
by ikegami (Pope) on Feb 15, 2007 at 16:01 UTC

    You can use MIME::Lite to send mail.

    Even if there was a mail command,
    "xxxxxx@xxxxx.com
    would need to be
    "xxxxxx\@xxxxx.com"
    or
    'xxxxxx@xxxxx.com'

Reaped: *DUP* Re: Okay I have cleaned it up a little bit
by NodeReaper (Curate) on Feb 15, 2007 at 16:02 UTC
Re: Okay I have cleaned it up a little bit
by nimdokk (Vicar) on Feb 15, 2007 at 16:42 UTC
    I don't think you need the newline (\n) at the end of your system command.
Re: Okay I have cleaned it up a little bit
by exussum0 (Vicar) on Feb 15, 2007 at 17:08 UTC
    If you are a seasoned programmer, I REALLY suggest looking at the perlsyn and perlfunc man pages. There's probably a better place to find them than through google, but it gets you what you need for now. It sounds like you are mixing up what perl's core functions are and what's available on the command line.

    If you aren't at all a seasoned (unseasoned?) programmer, I'd suggest finding the most relevant language about, learn the fundamentals of programming, such as loops, variables, data structures and what not.

      OP's pretty clearly not a seasoned programmer or he would know the difference between a program and an operating system. Very likely he would know the difference between a batch language and a scripting or programming language even.

      However, Perl is a pretty good language for teaching people many programming fundamentals (and pretty seriously cools as well). It is rather more forgiving than the more strongly typed languages and more quietly powerful (for some definition of powerful) than the many variants of Basic.

      So even for people with green scaly skin that live under a bridge, Perl is a pretty good place to learn something about what a programming language is and does.


      DWIM is Perl's answer to Gödel
        I prepare for the worst and hope for the best. Honestly, I can't think of many languages that are bad at teaching fundamentals. Assembler? If you stay away from pointers, C?
        OP's pretty clearly not a seasoned programmer or he would know the difference between a program and an operating system. Very likely he would know the difference between a batch language and a scripting or programming language even.

        He's most probably a seasoned DOS batch file hacker. His claims about being "a seasoned programmer" either imply he's been an amateur one, which is perfectly respectable, or else, if he means that he's been doing so professionally, are hard to believe. If he's sincere, I'd be very curious to know who's been paying him to concoct .bat files up to the present day. And to actually do what?

        OTOH, despite some comments I'm convinced that the OP is not a troll: appearently something or someone gave him the idea that "PERL" is a substitute or analogue or even a portage of DOS batch file interpreter, and I'd be very curious to know what or who this something or someone could be. Maybe because he read somewhere that Perl is used for system administration?

        However, Perl is a pretty good language for teaching people many programming fundamentals (and pretty seriously cools as well). It is rather more forgiving than the more strongly typed languages and more quietly powerful (for some definition of powerful) than the many variants of Basic.

        Isn't Pascal used any more as the first language for teaching? I haven't received formal programming instruction, but I guess Java is also very popular in this sense, nowadays. All in all, disrespectfully of my dislike for the latter, I think it's a rather good choice.

        So even for people with green scaly skin that live under a bridge, Perl is a pretty good place to learn something about what a programming language is and does.

        I don't know. I'm half hearted: of course I love Perl so much, and out of many languages I've tried it's the only one I did stick with. But for teaching I think that something more regular and less wild would be more appropriate...

        OP's pretty clearly not a seasoned programmer or he would know the difference between a program and an operating system. Very likely he would know the difference between a batch language and a scripting or programming language even.

        He's coming from Windoze. I've encountered a number of people like him. They usually have 10+ years of Windoze working at a small company, usually as the #2 or #3 IT person there. They believe that .bat files are the ultimate in user written programs, that .exe files can only be produced by mega corporations, and have not a bit of understanding of programs, operating systems, or other "advanced" concepts.

        Just be glad he's starting to break out of this and learn something new. What I'm wondering is how his company ended up with a "Sun machine" and what person put him on that project.

Re: Okay I have cleaned it up a little bit
by Joost (Canon) on Feb 15, 2007 at 17:39 UTC
Re: Okay I have cleaned it up a little bit
by blazar (Canon) on Feb 15, 2007 at 17:47 UTC
    I have taken your computer feedback to heart and cleaned up my code a little bit - I think this a lot more perl like and pretty technical.

    Indeed this does look more like Perl, but code must not be "perl like", it must have valid Perl syntax... well, if you want it to be valid Perl, and the program to work, that is. Also, it doesn't seem "pretty technical". It seems pretty basic, errors apart.

    #!/usr/bin/perl -w use strict;

    It's very very good that you're under strictures and warnings, but with recent enough perls it's better (i.e. more flexible) to

    use warnings; # rather than -w
    system "netbackup/bin/admincmd/bpdbjobs -report -all_columns\n";

    You don't need that \n. Nay, I would have thought it to issue an error, but I checked and that's not the case. Whatever, it's still confusing at best. Also, it's better to use the multiple args form of system.

    mail "xxxxxx@xxxxx.com

    There's no mail() Perl builtin:

    campari:~ [18:37:59]$ perldoc -f mail No documentation for perl function `mail' found

    See? And even if there were, you have an incomplete statement. The above should read:

    mail "xxxxxx\@xxxxx.com";

    Notice that I quoted the @ sign, for otherwise perl would interpret that as if you wanted to interpolate the @xxxxx array into your string, because yes: double quoted strings interpolate (scalars and arrays). Else, you would use a single quoted string, like thus:

    mail 'xxxxxx@xxxxx.com';
    but still I get:
    Bareword "com" not allowed while "strict subs" in use at ./nb.pl line +7.<br> Unquoted string "com" may clash with future reserved word at ./nb.pl l +ine 7.<br> Execution of ./nb.pl aborted due to compilation errors. <br>

    I don't trust you! That cannot be your actual program. When I run perl -c on it I get

    String found where operator expected at foo2.pl line 7, at end of line (Missing semicolon on previous line?) Can't find string terminator '"' anywhere before EOF at foo2.pl line 7 +.

    instead, which makes much more sense as an error message.

    BTW: what's with those <br>'s anyway?

Re: Okay I have cleaned it up a little bit
by geekphilosopher (Friar) on Feb 15, 2007 at 18:50 UTC
    Surely there's some sort of policy on PerlMonks about feeding the trolls?

    UPDATE: The number of downvotes I've received makes me think that no, there's no such policy :P
Re: Okay I have cleaned it up a little bit
by johngg (Abbot) on Feb 15, 2007 at 19:55 UTC
    ikegami has advised the use of MIME::Lite but note that it is not a core part of Perl and would need to be loaded by your local friendly sysadm. (or your good self if you fill that role).

    blazar has given a lot of good advice. I think it might be useful to expand on the use of system and how you would check that the command you ran succeeded or not. When you run a command it finishes with an exit status and, by convention, success is signified by an exit status of zero. When running from the shell in a terminal window of some sort you can check the exit status by examining a shell built-in variable, $? on Bourne and Korn shells (/bin/sh and /bin/ksh) or $status if using the C-shell (/bin/csh). You can do echo $SHELL to find out which you are using. Using the Korn shell you can see what happens when I do an ls on existent and non-existent files

    $ touch goodfile $ ls goodfile goodfile $ echo $? 0 $ ls badfile badfile: No such file or directory $ echo $? 2 $

    If I do the same thing using system in a Perl script (in this case actually typed in at the command line) I can still examine the exit status, this time using a Perl built-in variable also called $?. This time, however, there is more information available; see the system man page for the gory details but the bottom line is you have to shift $? right 8 bits to get the exit status. Like this

    $ perl -le ' > @cmd = qw{ls goodfile}; > system @cmd; > exit unless $?; > print $?, q{ - }, $? >> 8;' goodfile $ perl -le ' > @cmd = qw{ls badfile}; > system @cmd; > exit unless $?; > print $?, q{ - }, $? >> 8;' badfile: No such file or directory 512 - 2 $

    So, the point of the above is that it is good practice to check that your command actually ran rather than trusting to fate.

    If you are wanting to capture the output of your bpdbjobs command in order to send it in an email you should be using backticks or qx{ ...}, ($output = `command`; or $output = qx{command};) instead of system. There are references on the system manual page to follow if that is what you want.

    I hope you find this helpful.

    Cheers,

    JohnGG

    Update: Corrected cut'n'paste error in the last paragraph.

Re: Okay I have cleaned it up a little bit
by robot_tourist (Hermit) on Feb 16, 2007 at 10:15 UTC

    I was kind of looking forward to Kevin_Raymond's next post, but this is a bit of an anti-climax.

    At the risk of actually giving sound advice, I think you need ksh rather than the full power of Perl.

    How can you feel when you're made of steel? I am made of steel. I am the Robot Tourist.
    Robot Tourist, by Ten Benson

      thanks robot tourist - I actually took your advice and went with KSH after doing a little research I found that this is a useful tool and much better suited for what I was trying to achieve. A coworker showed me "CORN" I automated job scheduler that exists in Solaris. He was kind enough to put the script in there so now it runs every morning! My next task is to write a reporting tool on the internet! or the local company internet I mean. Thanks for the tip

      KR
      ***please respect President Bush***

        For more trolling experience:

        ***please respect President Bush***

        Why?

        Update: Ok, due to negative reactions as evidenced by massive downvoting, I repent and <strike> over the above, not because I think that my rethorical/sarcastic question is not legitimate -actually I think it is-, but because if the OP is really a troll as facts now strongly suggest, then fighting trolling by means of further troll-feeding is not going to be a particularly smart strategy. BTW: the same fate will affect my other node of the same nature.

        Kevin,

        Some people think that you are systematically posting comments that will set other people off on purpose - this is called "Trolling" and those who act in this way are called "Trolls".

        Judging from your opening comments it seems like you're not doing it on purpose, that you don't understand any of the Perl culture and are trying to break your way in & having a frustrating time doing so. People will correct you without explanation or not take you seriously and perhaps you don't know why. I will try to be more gentle, for the sake of someone else who might be having such a hard time who might come along & read this in the future.

        A coworker showed me "CORN" I automated job scheduler that exists in Solaris.

        In fact that utility is called cron.

        If you are looking at ksh, that is pronounced "Korn Shell", which may be the source of the confusion.

        Now, if you are indeed a Troll, as many have accused you of - then this sort of mistake was made on purpose in order to get people to correct you & draw attention to yourself for whatever reason.

        If that was the case then having a signature that asks people to "please respect" a controversial leader could also be considered to be inflammatory and perhaps was calculated for that effect. It also could be the heartfelt signature of a GOP constituent. Since it's not easy to tell the difference, I'll give you the benefit of the doubt if only to retain a sense of decorum in the monastery.



        Wait! This isn't a Parachute, this is a Backpack!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (16)
As of 2014-11-26 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls