[26759] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8835 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 6 18:05:17 2006

Date: Fri, 6 Jan 2006 15:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 6 Jan 2006     Volume: 10 Number: 8835

Today's topics:
        [OT] Re: calling subroutine , name derived from variabl <vdheuv.losetheMouse@kabelMickeyfoon.nl>
    Re: calling subroutine , name derived from variable <tadmc@augustmail.com>
    Re: calling subroutine , name derived from variable <noreply@gunnar.cc>
        regex question <rkapur@mpr.org>
    Re: regex question <tadmc@augustmail.com>
        system calls (mv + grep) within Perl script <wh2leung@student.cs.uwaterloo.ca>
    Re: system calls (mv + grep) within Perl script xhoster@gmail.com
    Re: system calls (mv + grep) within Perl script <wh2leung@student.cs.uwaterloo.ca>
    Re: system calls (mv + grep) within Perl script <jgibson@mail.arc.nasa.gov>
    Re: system calls (mv + grep) within Perl script <tadmc@augustmail.com>
        Using a package that might not be available <fbonews1@gmx.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 6 Jan 2006 23:39:14 +0100
From: "Theo  van den Heuvel" <vdheuv.losetheMouse@kabelMickeyfoon.nl>
Subject: [OT] Re: calling subroutine , name derived from variable
Message-Id: <43bef191$0$45483$58c7af7e@news.kabelfoon.nl>

<robic0> schreef in bericht 
news:1ttrr1dn4lhunfsu8nvpve6gkqesur5jjf@4ax.com...
> Don't ever, ever take any class I teach...

It took me a while to recover from this. I think a gentle hint
is called for. You shouldn't teach. You shouldn't teach, because
you suffer from a disposition for which, if I recall correctly,
the official medical term is stupidity. Not a mild form of it,
but the rarest variety of unmitigated, terminal stupidity.
You have proven this time and again. As a recent example,
I remember your rants on parsing when you tried to tackle
XML with regexes. So I urge you: do consider your pupils.
They might learn something from you. You should definitely
not teach.




------------------------------

Date: Fri, 6 Jan 2006 13:56:13 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <slrndrtiqt.f2i.tadmc@magna.augustmail.com>

Madhu Ramachandran <madhuram@nortel.com> wrote:

> Thank you very much for the help.


You are not fooling anyone.

If you truly were thankful, then you would follow the quoting
conventions that folks expect here (and nearly everywhere else too).



DO NOT TOP POST!

DO NOT FULL-QUOTE!

Please stop abusing us!


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 06 Jan 2006 23:10:07 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <428827F1go40eU1@individual.net>

Matt Garrish wrote:
> Gunnar Hjalmarsson wrote:
>>Gunnar Hjalmarsson wrote:
>>>

<code using symref snipped>

>>The above solution 'works', but I'd better admit that it's actually a 
>>symref, even if it passes strict. Matt's solution was criticized by that 
>>robic0 character, which proves that Matt provided a better answer.
> 
> ROTFL! I'll take the compliment... : )

For the sake of completeness, the applicable FAQ entry:

     perldoc -q "variable name"

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Fri, 6 Jan 2006 13:36:16 -0600
From: "Rajesh Kapur" <rkapur@mpr.org>
Subject: regex question
Message-Id: <11rthlhh6m5br78@corp.supernews.com>

Hello,

I am developing perl5 logic that needs to replace blocks of code from source 
files with a replacement block of code. My solution is to provide the old 
and new multi-line structure pairs in a parameter file like this

FROM
Code line 1
   Code line 2 etc
END-FROM
TO
    New Code Line 1
END-TO
FROM
 ...
 ...
END-FROM
TO
 ...
END-TO
etc..

The perl program reads this parameter file to load the translation pairs 
into the memory. Then it slurps the entire source code into a single string 
and applies regex substitutions from the array. After that it splits the 
code delimited by new-line into an array and then out into a flat file. It 
works well for the most part except that the FROM block has braces ( ) and . 
characters which are interpreted by the s/// command as special characters. 
The translation occurs successfully if I put a \ before all the special 
characters in the FROM blocks.

Questions:

Is there a better way to handle this kind of code-block translation?
Is there a way to prevent s/// command to NOT interpret '(' and '.' etc as 
special characters?

Thanks!
- Rajesh 




------------------------------

Date: Fri, 6 Jan 2006 16:07:39 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regex question
Message-Id: <slrndrtqhb.f9m.tadmc@magna.augustmail.com>

Rajesh Kapur <rkapur@mpr.org> wrote:

> I am developing perl5 logic that needs to replace blocks of code from source 
> files with a replacement block of code.

> Questions:
> 
> Is there a better way to handle this kind of code-block translation?


   man patch


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 6 Jan 2006 15:19:26 -0500
From: William <wh2leung@student.cs.uwaterloo.ca>
Subject: system calls (mv + grep) within Perl script
Message-Id: <Pine.GSO.4.64.0601061430210.25159@cpu02.student.cs.uwaterloo.ca>

code in question:
#!/usr/bin/perl -w

use strict;

my $InputFileDir = "/mkapp/webapps/mxrt-cgi/upload_vol/uploaded_files/";
my $savedfilename = "trs_vol.txt.49.22.224.132.LEUNGW5.20060106.13.11.42";
my $requiredList = "trs_vol.txt";
my $dummy_list = "dummylist.txt";

my $originalList = $InputFileDir . $savedfilename;
my $originalListBack = $InputFileDir . $requiredList;

open ( DUMMY_FD, $dummy_list ) || die "Cannot open file $dummy_list\n";
my @lines = <DUMMY_FD>;
close ( DUMMY_FD );

my $start;
my $ticker;
my $bo_fo_eligible;
my $lfo_eligible;

foreach my $currentLine ( @lines )  {
    ($start, $ticker, $bo_fo_eligible, $lfo_eligible) = ( split(/\|/, 
$currentLine) );
    system "grep ''$ticker' $originalList' >> $requiredList";
}


Error message:
grep: can't open AA 
/mkapp/webapps/mxrt-cgi/upload_vol/uploaded_files/trs_vol.txt.49.22.224.132.LEUNGW5.20060106.13.11.42
grep: can't open SUNW 
/mkapp/webapps/mxrt-cgi/upload_vol/uploaded_files/trs_vol.txt.49.22.224.132.LEUNGW5.20060106.13.11.42

contents of dummylist.txt:
|USD AA|1|0|name@uwaterloo.ca
|USD SUNW|0|1|name@uwaterloo.ca

contents of trs_vol.txt.49.22.224.132.LEUNGW5.20060106.13.11.42:
|USD AA|USD 
NYSE|Securities|1D|0|ATM|18.222100000000001|18.222100000000001|^M
|USD AA|USD 
NYSE|Securities|3D|0|ATM|19.222100000000001|19.222100000000001|^M
|USD AA|USD NYSE|Securities|1W|0|ATM|20.8015|20.8015|^M
|USD AA|USD NYSE|Securities|2W|0|ATM|21.4873|21.4873|^M
|USD AA|USD NYSE|Securities|3W|0|ATM|22.2561|22.2561|^M
|USD AA|USD 
NYSE|Securities|1M|0|ATM|25.994400000000002|25.994400000000002|^M
|USD AA|USD NYSE|Securities|3M|0|ATM|25.1098|25.1098|^M
|USD AA|USD 
NYSE|Securities|4M|0|ATM|25.313000000000002|25.313000000000002|^M
|USD AA|USD 
NYSE|Securities|6M|0|ATM|25.668999999999997|25.668999999999997|^M
|USD AA|USD 
NYSE|Securities|9M|0|ATM|26.104699999999998|26.104699999999998|^M
|USD AA|USD 
NYSE|Securities|1Y|0|ATM|26.466299999999997|26.466299999999997|^M
|USD AA|USD 
NYSE|Securities|1D|0|ATM|18.222100000000001|18.222100000000001|^M
|USD AA|USD 
NYSE|Securities|3D|0|ATM|19.222100000000001|19.222100000000001|^M
|USD AA|USD NYSE|Securities|1W|0|ATM|20.8015|20.8015|^M
|USD AA|USD NYSE|Securities|2W|0|ATM|21.4873|21.4873|^M
|USD AA|USD NYSE|Securities|3W|0|ATM|22.2561|22.2561|^M
|USD AA|USD 
NYSE|Securities|1M|0|ATM|25.994400000000002|25.994400000000002|^M
|USD AA|USD NYSE|Securities|3M|0|ATM|25.1098|25.1098|^M
|USD AA|USD 
NYSE|Securities|4M|0|ATM|25.313000000000002|25.313000000000002|^M
|USD AA|USD 
NYSE|Securities|6M|0|ATM|25.668999999999997|25.668999999999997|^M
|USD AA|USD 
NYSE|Securities|9M|0|ATM|26.104699999999998|26.104699999999998|^M
|USD AA|USD 
NYSE|Securities|1Y|0|ATM|26.466299999999997|26.466299999999997|^M

Question:

I am trying to grep for "USD AA" and "USD SUNW".  What is the proper way 
to "grep"?



------------------------------

Date: 06 Jan 2006 20:56:25 GMT
From: xhoster@gmail.com
Subject: Re: system calls (mv + grep) within Perl script
Message-Id: <20060106155625.151$Mo@newsreader.com>

William <wh2leung@student.cs.uwaterloo.ca> wrote:

>     system "grep ''$ticker' $originalList' >> $requiredList";
 ...
>
> Error message:
> grep: can't open AA
> /mkapp/webapps/mxrt-cgi/upload_vol/uploaded_files/trs_vol.txt.49.22.224.1
> 32.LEUNGW5.20060106.13.11.42 grep: can't open SUNW
> /mkapp/webapps/mxrt-cgi/upload_vol/uploaded_files/trs_vol.txt.49.22.224.1
> 32.LEUNGW5.20060106.13.11.42
>...
>
> I am trying to grep for "USD AA" and "USD SUNW".  What is the proper way
> to "grep"?

You could do the grep from within Perl.  Then at least you would have a
real perl question, rather than a shell and/or gnu utility question.

Anyway, I'd think not sprinkling single quotes around at random would
help.  Maybe this is what you meant?:

system "grep '$ticker' '$originalList' >> $requiredList";

You alse might need to chomp some stuff, or strip \r characters.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: Fri, 6 Jan 2006 16:02:28 -0500
From: William <wh2leung@student.cs.uwaterloo.ca>
Subject: Re: system calls (mv + grep) within Perl script
Message-Id: <Pine.GSO.4.64.0601061601120.25159@cpu02.student.cs.uwaterloo.ca>

On Fri, 6 Jan 2006, xhoster@gmail.com wrote:

> William <wh2leung@student.cs.uwaterloo.ca> wrote:
>
>>     system "grep ''$ticker' $originalList' >> $requiredList";
> ...
>>
>> Error message:
>> grep: can't open AA
>> /mkapp/webapps/mxrt-cgi/upload_vol/uploaded_files/trs_vol.txt.49.22.224.1
>> 32.LEUNGW5.20060106.13.11.42 grep: can't open SUNW
>> /mkapp/webapps/mxrt-cgi/upload_vol/uploaded_files/trs_vol.txt.49.22.224.1
>> 32.LEUNGW5.20060106.13.11.42
>> ...
>>
>> I am trying to grep for "USD AA" and "USD SUNW".  What is the proper way
>> to "grep"?
>
> You could do the grep from within Perl.  Then at least you would have a
> real perl question, rather than a shell and/or gnu utility question.

I am relatively new to Perl.
how to "grep from within Perl" without using system?




------------------------------

Date: Fri, 06 Jan 2006 13:42:14 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: system calls (mv + grep) within Perl script
Message-Id: <060120061342145412%jgibson@mail.arc.nasa.gov>

In article
<Pine.GSO.4.64.0601061601120.25159@cpu02.student.cs.uwaterloo.ca>,
William <wh2leung@student.cs.uwaterloo.ca> wrote:

> On Fri, 6 Jan 2006, xhoster@gmail.com wrote:
> 
> > William <wh2leung@student.cs.uwaterloo.ca> wrote:
> >
> >>     system "grep ''$ticker' $originalList' >> $requiredList";
> > ...

> >>
> >> I am trying to grep for "USD AA" and "USD SUNW".  What is the proper way
> >> to "grep"?
> >
> > You could do the grep from within Perl.  Then at least you would have a
> > real perl question, rather than a shell and/or gnu utility question.
> 
> I am relatively new to Perl.
> how to "grep from within Perl" without using system?

Use regular expressions and the print command:

#!/usr/local/bin/perl
use strict;
use warnings;
my @search = (
  '|USD AA|1|0|name@uwaterloo.ca',
  '|USD SUNW|0|1|name@uwaterloo.ca'
);
my @data_lines = <DATA>;
foreach my $pattern ( @search )  {
  my (undef, $ticker) = ( split(/\|/, $pattern), 2 );
  print "\nLooking for $ticker:\n";
  foreach ( @data_lines ) {
    print if /\Q$ticker\E/;
  }
}
__DATA__
|USD AA|USD NYSE|Securities|1D|0|ATM|18.222100000000001|...
|USD AA|USD NYSE|Securities|3D|0|ATM|19.222100000000001|...
|USD AA|USD NYSE|Securities|1W|0|ATM|20.8015|20.8015|
|USD AA|USD NYSE|Securities|2W|0|ATM|21.4873|21.4873|
|USD AA|USD NYSE|Securities|3W|0|ATM|22.2561|22.2561|
etc

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Fri, 6 Jan 2006 16:39:07 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: system calls (mv + grep) within Perl script
Message-Id: <slrndrtscb.f9m.tadmc@magna.augustmail.com>

William <wh2leung@student.cs.uwaterloo.ca> wrote:


> Subject: system calls (mv + grep) within Perl script


There is no "mv" anywhere in your article.

It there had been, then I would have pointed you to:

   perldoc rename

but you didn't, so I won't.


> #!/usr/bin/perl -w


Lexical warnings are much better than global warnings, so you should
enable warnings this way instead:

   use warnings;


> open ( DUMMY_FD, $dummy_list ) || die "Cannot open file $dummy_list\n";


You should include the _reason_ for the failure in your message.

It is also a good idea to put delimiters around the failed filename:

   open ( DUMMY_FD, $dummy_list ) || die "Cannot open file '$dummy_list' $!";


> my @lines = <DUMMY_FD>;
> close ( DUMMY_FD );


> foreach my $currentLine ( @lines )  {


Don't read the entire file into an array if all you plan to do is
process it line-by-line anyway.

Simply read it line-by-line in the first place:

   while ( my $currentLine = <DUMMY_FD> ) {

>     ($start, $ticker, $bo_fo_eligible, $lfo_eligible) = ( split(/\|/, 
> $currentLine) );
>     system "grep ''$ticker' $originalList' >> $requiredList";
                   ^^
                   ^^ you have messed up the quoting


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 06 Jan 2006 20:55:38 +0100
From: Frank Burkhardt <fbonews1@gmx.net>
Subject: Using a package that might not be available
Message-Id: <43becb3a$0$21036$9b4e6d93@newsread2.arcor-online.net>

Hi everyone,

I'm trying to use a cpan-package but I don't want to depend on it because
sometimes it's unavailable and there's an alternative (which is slower).

<problem>
use strict;
use foo::bar qw(MY_CONSTANT)

if ( defined(foo::bar) ) {
   foo::bar::foobar(MY_CONSTANT);
} else {
   system("foobar_slow");
}
</problem>

This example will not work, of course - but this one will - at least partly:

<partlysolved>
eval "use foo::bar qw(MY_CONSTANT);"

if ( $@ ne '' ) {
   foo::bar::foobar(MY_CONSTANT);
} else {
   system("foobar_slow");
}
</partlysolved>

Problems left:
   * MY_CONSTANT is not available when "use foo::bar" is done inside eval
   * I have a "non-strict"-script now but I like "strict" better :-( .

Does anyone know how to solve one or both of these problems?

Thank you,

Frank


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8835
***************************************


home help back first fref pref prev next nref lref last post