in reply to Vanishing Data

Grasshopper needs meditation first:
#!/usr/local/bin/perl -l use strict; foreach (0,'',undef) { print "'$_' is zero number" if $_ == 0; print "'$_' is zero string" if $_ eq '0'; print "'$_' is empty string" if $_ =~ /^$/; print "'$_' is empty string" if $_ eq ''; print "'$_' is undef" if ! defined $_; }

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: Vanishing Data
by thelenm (Vicar) on May 02, 2002 at 16:31 UTC
    It's a really minor point, but this statement is not strictly true:
    print "'$_' is empty string" if $_ =~ /^$/;
    What you want is /^\z/, since /^$/ will also match a single newline, as evidenced by the following test:
    print "Empty matches ^\$ --> ", ("" =~ /^$/ ? 'yes' : 'no'), "\n"; print "Newline matches ^\$ --> ", ("\n" =~ /^$/ ? 'yes' : 'no'), "\n" +; print "Empty matches ^\\z --> ", ("" =~ /^\z/ ? 'yes' : 'no'), "\n"; print "Newline matches ^\\z --> ", ("\n" =~ /^\z/ ? 'yes' : 'no'), "\n +";