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

I'm really embarassed for asking this. Or this could be another case of failing to RTFM.

I'm writing a little program to monitor my disks on my laptop, because I'm never too sure of the GUI tools on my CentOS/Gnome install. So I want to write a little Perl script to notify me when my disks are safe to remove, and I'm a noob writing scripts to learn. Since I heard that coding is one of the best ways to learn programming skills, and reading other code.

Anyway, I choose to write a little script to try my skills at working a little event loop, since my program will require some form of event loop.

Scratchpad http://perlmonks.org/?node_id=880110

I set some loop control variables, and then I go into my loop to write some noob-code to play around with the event loop. But my Perl interpreter keeps saying that '=: command not found'. So I can't define my loop control vars. I did use any lexical vars since this was supposed to be a quick and dirty little thing, but now it's been about two hours and I'm trying to make dinner at the same time.

Also, I tried to do a multi-line comment to layout my pseudo-code, but perl would not accept my comments in code when I used:
=for comment hey my comments go here along with some pseudocode: awesome_code( $var12 ) unless ( $response == 1 ); =cut

Replies are listed 'Best First'.
Re: simple newb question
by stevieb (Canon) on Jun 13, 2012 at 00:08 UTC

    As was just pointed out to me recently, it is best to not use your scratchpad to post code in, as when someone checks this post out in the future, it is likely that code will change. If you don't mind, update your post to include the code instead of the link. For now, here it is:

    #usr/bin/perl -w #=for comment #pseudocode: #start event loop # gather input, then act on input # actions are print statements #=cut $quit = 0; $answer = "blank"; while ($quit == 0) { print "Do you want to loop?\n"; $answer = <STDIN>; print $answer; }

    From the looks of it, this code *should* run (untested), however because your shebang line is broken, the file won't process as code perl can interpret. It should be:

    #!/usr/bin/perl

    Beyond that, again, because you're not using

    use strict; use warnings;

    (which you should), you're not defining anything lexically.

    Furthermore, in the code you did actually include in your post, your code has to go underneath the =cut, not embraced in it.

    Update: you need to read perldoc perlpod. Also, if possible, perhaps you could retitle your post to something more descriptive such as "Problems with multiline comments" or some such.

    Update2: I'm kind of sorry for the Slashdot-style Consideration note. I can't explain why I did that as it has been so long since I've seen it used. It just came out ;) Also, the recommended title should have stated "Problems with perlpod", not perldoc.

Re: simple newb question
by choroba (Cardinal) on Jun 13, 2012 at 00:13 UTC
    Use [pad://filesurfer] or [pad://] to reference filesurfer's scratchpad.

    How do you run the script? I can run it just fine. The problem might be some other interpreter than perl is trying to run the script (you are missing the !/ signs in the shebang line).

Re: simple newb question
by filesurfer (Novice) on Jun 13, 2012 at 01:32 UTC
    OMG! Thank you for the help. It was a simple gaff I did. Yes I will slap myself for that, and thank you guys for the help. I will try and be more thorough with my debugging in the future.
    #usr/bin/perl -w #=for comment #pseudocode: #start event loop # gather input, then act on input # actions are print statements #=cut $quit = 0; $answer = "blank"; while ($quit == 0) { print "Do you want to loop?\n"; $answer = <STDIN>; print $answer; }

      Great job homie... but what I was hoping for, was you entering into your original post (OP) and fix that :) You're on your way! Also, while you're editing your OP, it would be cool if you could make the title more descriptive. I'm not trying to be disrespectful, I'm just trying to show you the ropes so that the Janitors don't have to exert energy ;)

      Keep up your good work.

        Please don't put non-trivial updates via editing a node (nor encourage others to do so). We have tons of tools for making it easier for people to notice which new nodes have been posted recently. We don't have (and never will have) good tools to make it easy for people to notice recent significant updates to nodes that they have already read and would like to keep up-to-date on the progress of that thread (not only because separating significant updates from trivial updates is a rather hard problem to do well).

        Non-trivial updates are best signaled by the creation of a new node (a new reply), especially when that new node actually contains the update.

        - tye