Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] Re: Eval and memory problems

Expand Messages
  • Boyle, Christopher
    perldoc -quote ________________________________ From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] On Behalf Of computerdribble Sent:
    Message 1 of 15 , Jan 8, 2008
      perldoc -quote


      From: perl-beginner@yahoogroups.com
      [mailto:perl-beginner@yahoogroups.com] On Behalf Of computerdribble
      Sent: Tuesday, January 08, 2008 3:38 PM
      To: perl-beginner@yahoogroups.com
      Subject: [PBML] Re: Eval and memory problems

      Thank you.

      I went onto the faq.perl.org site and searched through all of that
      and nothing came back.

      This is one of the problems and reasons I have stayed away from perl
      for so long. There's SO much to it and it HAS its OWN quirkiness that
      outpaces other languages.

      but again, thank you!

      Now, one other question....

      this works:
      $text =~ s/(\$\w+)/$1/eeg

      it takes;

      and inserts it into;

      $text = "( ( $aa =~ /lo/ ) and ($bb =~ /ye/ ) )";

      perfectly to create:

      ( ( hello =~ /lo/ ) and ( goodbye =~ /ye/ ) )

      notice the problem ? No quotes around the $aa expanded variable. So the
      if ( @{ [ $text ] } )

      always fails.

      I'm NOT a regex person and stumble my way through it so far.. but this
      is beyond me at the moment. (yes more reading is required)

      How do I get the expansion (or can it be done? ) to automatically put
      the quotes around the variables expanded?

      I can add the quotes into the database around the variables, but then
      its a cludge.

      thanks again and thanks in advance...


      --- In perl-beginner@yahoogroups.com
      <mailto:perl-beginner%40yahoogroups.com> , merlyn@... wrote:
      > >>>>> "computerdribble" == computerdribble <computerdribble@...>
      > computerdribble> Nope , not in there. there is nothing in the FAQ
      concerning Macro
      > computerdribble> expansion.
      > By the way, it's on *YOUR DISK*. No need to go off to the net for
      the FAQ.
      > Type "perldoc perlfaq". And you can search it too, which I will now
      do for
      > you, to show you the FAQ *does* cover what you're looking for.
      > I suggest you read the subject lines of "perldoc perlfaq" and
      "perldoc perl"
      > weekly until you can recite them from memory. Perl comes with a
      HUGE amount
      > of info, but it's pointless if you don't know what's there.
      > $ perldoc -q expand
      > Found in /usr/libdata/perl5/pod/perlfaq4.pod
      > How do I expand function calls in a string?
      > (contributed by brian d foy)
      > This is documented in perlref, and although it's not the easiest
      > to read, it does work. In each of these examples, we call the
      > inside the braces used to dereference a reference. If we have a more
      > than one return value, we can construct and dereference an anonymous
      > array. In this case, we call the function in list context.
      > print "The time values are @{ [localtime] }.\n";
      > If we want to call the function in scalar context, we have to do
      a bit
      > more work. We can really have any code we like inside the
      braces, so we
      > simply have to end with the scalar reference, although how you
      do that
      > is up to you, and you can use code inside the braces.
      > print "The time is ${\(scalar localtime)}.\n"
      > print "The time is ${ my $x = localtime; \$x }.\n";
      > If your function already returns a reference, you don't need to
      > the reference yourself.
      > sub timestamp { my $t = localtime; \$t }
      > print "The time is ${ timestamp() }.\n";
      > The "Interpolation" module can also do a lot of magic for you.
      You can
      > specify a variable name, in this case "E", to set up a tied hash
      > does the interpolation for you. It has several other methods to
      do this
      > as well.
      > use Interpolation E => 'eval';
      > print "The time values are $E{localtime()}.\n";
      > In most cases, it is probably easier to simply use string
      > which also forces scalar context.
      > print "The time is " . localtime . ".\n";
      > How do I expand tabs in a string?
      > You can do it yourself:
      > 1 while $string =~ s/\t+/' ' x (length($&) * 8 - length($`)
      % 8)/e;
      > Or you can just use the Text::Tabs module (part of the standard Perl
      > distribution).
      > use Text::Tabs;
      > @expanded_lines = expand(@lines_with_tabs);
      > How can I expand variables in text strings?
      > Let's assume that you have a string that contains placeholder
      > $text = 'this has a $foo in it and a $bar';
      > You can use a substitution with a double evaluation. The first
      /e turns
      > $1 into $foo, and the second /e turns $foo into its value. You
      may want
      > to wrap this in an "eval": if you try to get the value of an
      > variable while running under "use strict", you get a fatal error.
      > eval { $text =~ s/(\$\w+)/$1/eeg };
      > die if $@;
      > It's probably better in the general case to treat those variables as
      > entries in some special hash. For example:
      > %user_defs = (
      > foo => 23,
      > bar => 19,
      > );
      > $text =~ s/\$(\w+)/$user_defs{$1}/g;
      > --
      > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
      777 0095
      > <merlyn@...> <URL:http://www.stonehenge.com/merlyn/
      <http://www.stonehenge.com/merlyn/> >
      > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      > See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl

      This email has been scanned by the MessageLabs Email Security System.
      For more information please visit http://www.messagelabs.com/email

      NOTICE OF CONFIDENTIALITY: Information included in and/or attached to this electronic mail transmission may be confidential. This electronic mail transmission is intended for the addressee(s) only. Any unauthorized disclosure, reproduction, or distribution of, and/or any unauthorized action taken in reliance on the information in this electronic mail is prohibited. If you believe that you have received this electronic mail transmission in error, please notify the sender by reply transmission, or contact helpdesk@..., and delete the message without copying or disclosing it.

      This email has been scanned by the MessageLabs Email Security System.
      For more information please visit http://www.messagelabs.com/email

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.