Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Possible bug in Perl?

by Lhamo_rin (Friar)
on Jul 26, 2005 at 13:23 UTC ( [id://478173]=perlquestion: print w/replies, xml ) Need Help??

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

Fellow monks, I have come across a problem that I cannot explain. In the following code I am using the system command to read in two points from a database. For some reason, both values, $a and $b are being printed out. If I comment out the last line, just one value is printed to the screen. But with the last line in, it prints out the value of $a and $b. How can $b be printed out when it has not even read the point yet? I'm using version 5.6. Any ideas?
#!/usr/local/bin/perl -w use diagnostics; my $a = system "read_apt db_1"; print $a; my $b = system "read_apt db2";

Replies are listed 'Best First'.
Re: Possible bug in Perl?
by tlm (Prior) on Jul 26, 2005 at 13:26 UTC

    I bet it's the system command that's doing the printing. See what you get if you comment out the print statement.

    the lowliest monk

Re: Possible bug in Perl?
by jeteve (Pilgrim) on Jul 26, 2005 at 13:30 UTC
    Is your read_apt command outputs something to stdout ? System returns the exit code of the command, not the stdout of it. Try backticks to get the stdout of the command:
    my $b = `read_apt db2` ;
    Nice photos of naked perl sources here !
      jeteve, is that last line written in your post part of the post, cause I went to the link and I couldn't see the relevance to the post..

      I'd have thought that a sig would be best represented in a smaller font, if one considers it absolutely essential to use such things..

        With CSS, you can make sigs look differently from the rest. For example, my custom CSS holds the code:
        div.pmsig, div.pmsig td, div.pmsig font { color: #988; background-color: #F0F0F9; }
        which makes the text greyish on greyish (for use on white background)

        Feel free to change the colours. :)

Re: Possible bug in Perl?
by tphyahoo (Vicar) on Jul 26, 2005 at 16:35 UTC
    $a and $b are default variables used for sorting in perl. That may not be the root of the problem, but then again... maybe it is. If you try the code using other two variables and it works, you know the problem is the default var thing. Google on perlvar. (I would love to link to perldoc.com or perlmonks, but perlmonks is out of date and perldoc is down > 90% of the time, grrr.)
Re: Possible bug in Perl?
by spiritway (Vicar) on Jul 27, 2005 at 03:11 UTC

    Try renaming $a and $b to something else. Those variables are used in sort comparisons. Check out, for example, Programming Perl, 3rd Ed., p. 654.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-28 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found