logo       

RE: s/// w/o intermediate variables?: msg#00020

Subject: RE: s/// w/o intermediate variables?
use File::Spec;
my $package = 'Foo::Bar::Baz';
require File::Spec->catfile(split /::/, $package);


more generally, this works for me:

$tranformed = map {local $_=$_; s,::,/,g; $_} $package

Greg

-----Original Message-----
From: kynn@xxxxxxxxx [mailto:kynn@xxxxxxxxx] 
Sent: Tuesday, May 04, 2004 4:14 PM
To: fwp@xxxxxxxx
Subject: s/// w/o intermediate variables?






Here's an example of a recurrent annoyance:

  my $package = 'Foo::Bar::Baz';
  (my $package_filename = $package) =~ s,::,/,g;
  require $package_filename;
  $package->foobar();

One of my many neurotic little peeves is that, unless code readability
absolutely demands it, I hate defining variables that will be used
only once, such as $package_filename above.  I would like to be able
to do something like

  my $package = 'Foo::Bar::Baz';
  require TRANSFORM[ s,::,/,g, "$package.pm" ];
  $package->foobar();

where TRANSFORM[] stands for an expression in which an "s-expression"
(i.e. one using s///) is applied to a string, and the resulting string
is returned as the result.

Of course, I could define a helper sub to do this:

  sub transform {
    my $s_expression = shift;
    local $_ = shift;
    eval $s_expression;
    die $@ if $@;
    $_
  }

But is there a way to achieve this result without defining such a
helper sub?

kynn

P.S. I couldn't come up with a sufficiently general transform sub such
that its first argument is a qr-quoted regexp.  Is there a way to do
this that approaches the level of generality of the eval kluge above?


------------------------------------------------------------------------------
This message is intended only for the personal and confidential use of the
designated recipient(s) named above.  If you are not the intended recipient of
this message you are hereby notified that any review, dissemination,
distribution or copying of this message is strictly prohibited.  This
communication is for information purposes only and should not be regarded as
an offer to sell or as a solicitation of an offer to buy any financial
product, an official confirmation of any transaction, or as an official
statement of Lehman Brothers.  Email transmission cannot be guaranteed to be
secure or error-free.  Therefore, we do not represent that this information is
complete or accurate and it should not be relied upon as such.  All
information is subject to change without notice.




<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