Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: getting 0 to print

by RMGir (Prior)
on Jan 13, 2003 at 20:39 UTC ( [id://226587]=note: print w/replies, xml ) Need Help??


in reply to getting 0 to print

I think the culprit is in sub trim:
if (!($_)) { $_ = ""; }
You're asking it to make 0's go away...
--
Mike

Replies are listed 'Best First'.
Re: Re: getting 0 to print
by rbc (Curate) on Jan 13, 2003 at 20:51 UTC
    Thank you wise monk yet if I modify my sub trim to ...
    55 sub trim { 56 my @out = @_; 57 if ( !defined(@_)) {return "";} 58 if ( $#out == -1 ) {return "";} 59 for(@out) { 60 #next if !($_); 61 #if (!($_)) { $_ = ""; } 62 s/^\s+//; 63 s/\s+$//; 64 s/\|//g; 65 s/\n//g; 66 s/\cM//g; 67 s/\r//g; 68 } 69 return wantarray ? @out : $out[0]; 70}
    ... I get these messages ...
    Use of uninitialized value in join or string at ./b.pl line 49
    Use of uninitialized value in join or string at ./b.pl line 62
    Use of uninitialized value in join or string at ./b.pl line 63
    ... etc 
    
    I would like to not have any extraneous output.
    Any suggestion?

      You appear to be passing undefined values to your trim routine. If you want to substitute an empty string for undefined values, test with defined. if (!$_) is true for 0 and undefined values and your code was substituting an empty string for either. I think you only wanted the substitution for undefined values.

      59 for(@out) { 60 #next if !($_); 61 if (!defined $_) { $_ = ""; } 62 s/^\s+//; 63 s/\s+$//; 64 s/\|//g; 65 s/\n//g; 66 s/\cM//g; 67 s/\r//g; 68 }
      --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
        Ah yes!
        if (!defined $_) { $_ = ""; }
        is most wise.
        Thank you O wise monk.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found