logo       

Re: Error puzzler: msg#00033

Subject: Re: Error puzzler
From the keyboard of Peter Scott [13.09.06,09:20]:

> Here's a distillation of something that just bit me, behaves the same on
> 5.6.1 and 5.8.5.  Observe the following program:

Try this :-)

$_ = "bar";
print "before the loop: \$_ = $_\n";
for (1..1) {
  print "before print_file(): \$_ = $_\n";
  print_file($0);
  print "after print_file(): \$_ = $_\n";
}

sub print_file {
  print "before while: \$_ = $_\n";
  local @ARGV = shift;
  while (<>) { print }
  print "after while: \$_ = $_\n";
  $_ = "foo";
}
print "before __END__: \$_ = $_\n";
__END__

gives:

before the loop: $_ = bar
before print_file(): $_ = 1
before while: $_ = 1
$_ = "bar";
print "before the loop: \$_ = $_\n";
for (1..1) {
  print "before print_file(): \$_ = $_\n";
  print_file($0);
  print "after print_file(): \$_ = $_\n";
}

sub print_file {
  print "before while: \$_ = $_\n";
  local @ARGV = shift;
  while (<>) { print }
  print "after while: \$_ = $_\n";
  $_ = "foo";
}
print "before __END__: \$_ = $_\n";
__END__
after while: $_ =
after print_file(): $_ = foo
before __END__: $_ = bar

> Before running it, can you tell:
>   Will it succeed or not?
>   If not, with what error?
>   Where?
>   Why?

The error is thrown at the moment the <> oprator tries to assign to $_,
which is an alias to a constant - the '1'.

Common pitfall ;-)

The <> operator does no further aliasing, it operates upon $_ at it's
"current aliasing level".

0--gg-

-- 
_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s,/,($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e,e && print}




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe