[21936] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4158 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 22 00:06:00 2002

Date: Thu, 21 Nov 2002 21:05:11 -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           Thu, 21 Nov 2002     Volume: 10 Number: 4158

Today's topics:
    Re: "use of uninitialized value" when all values are in <garry@ifr.zvolve.net>
    Re: "use of uninitialized value" when all values are in <mgjv@tradingpost.com.au>
    Re: Checking for human user with images <wsegrave@mindspring.com>
    Re: Convert form input by using a hash <kevin@wx3.com>
    Re: evenly distribute array based on percentage (Mike Cardeiro)
    Re: Format  a one line file to get two columns <krahnj@acm.org>
        how to split backslash <guozhang@cisco.com>
    Re: how to split backslash <ian@WINDOZEdigiserv.net>
        List of all modules w/ versions <idontreadthis56@hotmail.com>
    Re: List of all modules w/ versions <twhu@lucent.com>
    Re: List of all modules w/ versions (Walter Roberson)
        Missing ..\Perl\lib\auto\Mail\Internet\autosplit.ix <No_Mail_Address@cox.net>
        NYC <aaaaaaaaaaa@oh.org>
    Re: NYC <jurgenex@hotmail.com>
    Re: passing address between classes - OO type question (kit)
    Re: Perl one-liners in Win32 <fixerdave@hot-NoSpamPlease-mail.com>
    Re: Perl one-liners in Win32 <fixerdave@hot-NoSpamPlease-mail.com>
    Re: Perl one-liners in Win32 <fixerdave@hot-NoSpamPlease-mail.com>
    Re: regex subroutine \) passing variables SOLVED <lance@augustmail.com>
        regexp help <lance@augustmail.com>
    Re: regexp help <wksmith@optonline.net>
        shtml and Perl <tjalbout@hotmail.com>
    Re: Why can't code print an @array?? <miscellaneousemail@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 22 Nov 2002 01:56:23 -0000
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: "use of uninitialized value" when all values are initiatlized?
Message-Id: <slrnatr3m6.7hj.garry@zfw.zvolve.net>

On Thu, 21 Nov 2002 01:31:10 GMT, Carlos C Gonzalez
<miscellaneousemail@yahoo.com> wrote:
> In article <3DDC07A4.7030302@vpservices.com>, jeff@vpservices.com
> says...
> 
>> > #!/usr/bin/perl
>> 
>> 
>> No warnings????
>> 
> [some snipped]
> 
> Thanks for your input Jeff.  As I told Tad I just didn't see it.  
> 
> As for warnings I guess I should put a -W in there when I ask
> questions about my code.  

It's -w, not -W.  

> The code actually does run with a "-W" from within my editor's Perl
> hot key.  I put the shebang line in my posted code mostly to keep
> down questions about why I am missing it.  Under Windows, Perl runs
> the code and doesn't even pay attention to the shebang line.  At
> least that's the way I have it set up.  

That's not true.  Check the perlrun manual page: 

     The #! line is always examined for switches as the line is
     being parsed.

By the way, the modern way to enable warnings is to `use warnings;'.  

-- 
Garry Williams


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

Date: Fri, 22 Nov 2002 02:34:52 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: "use of uninitialized value" when all values are initiatlized?
Message-Id: <slrnatr62o.mmn.mgjv@verbruggen.comdyn.com.au>

On Fri, 22 Nov 2002 01:56:23 -0000,
	Garry Williams <garry@ifr.zvolve.net> wrote:
> On Thu, 21 Nov 2002 01:31:10 GMT, Carlos C Gonzalez
><miscellaneousemail@yahoo.com> wrote:
>> 
>> As for warnings I guess I should put a -W in there when I ask
>> questions about my code.  
> 
> It's -w, not -W.  

Of course, unless you fiddle with $^W or have no warnings somewhere,
they're the same. But yes, generally -w is more than sufficient.

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | 42.6% of statistics is made up on the spot.
                        | 


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

Date: Thu, 21 Nov 2002 22:22:24 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Checking for human user with images
Message-Id: <arkcqn$bcp$1@slb9.atl.mindspring.net>

"Arnar Mar Hrafnkelsson" <addi@umich.edu> wrote in message
news:xfsvel9mx4z0.fsf@blue.engin.umich.edu...
>
> Sometimes you want to make an image that is 'not trivial' to
> OCR by a machine.  This is useful to defeat robots that submit
> to web forms and such.
>
> Example output of the method I use is at:
> http://www.eecs.umich.edu/~addi/perl/Imager/testing_sc.png
>
> The code follows:
<snip>
>
> A little note: Of course you need to replace the paths in here with
> something that makes sense on your machine.

Thanks, Arnar. Your script worked fine here.

Another little note: The user will also need to download and install the
Affix::Infix2Postfix module to get it to work. ;-)

Cheers.

Bill Segraves




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

Date: Fri, 22 Nov 2002 03:42:09 GMT
From: "Kevin Lin" <kevin@wx3.com>
Subject: Re: Convert form input by using a hash
Message-Id: <lIhD9.96010$NH2.6236@sccrnsc01>

$longMonthName{$input{n}}.

Or you could have done:
$test=$input{n};
print $longMonthName{$test}.

Maybe you tried that, but it won't work until you move %longMonthName to
before you call &conversion.
--
Kevin Lin
Wx3 Web Consulting
http://www.wx3.com/

"J.C.Castro" <jccastro@osite.com.br> wrote in message
news:9b76f2c0.0211100845.5769a37f@posting.google.com...
> The script below is an example of what I want to do, although I will
> not work with month names. But it has something wrong.
> _______________________________________________________________
>
> #!/usr/bin/perl
>
> &hent_input;
> &conversion;
>
> %longMonthName = ("Jan", "January",
>     "Feb", "February",
>     "Mar", "March",
>     "Apr", "April",
>     "May", "May",
>     "Jun", "June",
>     "Jul", "July",
>     "Aug", "August",
>     "Sep", "September",
>     "Oct", "October",
>     "Nov", "November",
>     "Dec", "December");
>
> $test = $input{n};
>
> sub hent_input {
>
> if ( $ENV{'REQUEST_METHOD'} eq "GET")  {
> $input = $ENV{'QUERY_STRING'};
> } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
> read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
> }
>
> @input = split (/&/, $input);
> foreach (@input) {
> s/\+/" "/g;
> ($name, $value) = split (/=/,$_);
>
> $name =~s/%(..)/pack("c",hex($1))/ge;
> $value =~s/%(..)/pack("c",hex($1))/ge;
> $input{$name} .= "\0" if (defined($input{$name}));
> $input{$name} .= $value;
> }
> }
>
> sub conversion {
> print "Content-type: text/html\n\n";
> print "$longMonthName{$test}\n";
> }
> ________________________________________________________________
>
> I know that this would work:
> $test = 'Nov';
> print "$longMonthName{$test}\n";
>
> And this also would work:
> print "$input{n}\n";
>
> But I don't know how to use $longMonthName{$test} when $test =
> $input{n}
>
> Thanks.




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

Date: 21 Nov 2002 18:31:04 -0800
From: mcardeiro@yahoo.com (Mike Cardeiro)
Subject: Re: evenly distribute array based on percentage
Message-Id: <63ac3571.0211211831.2e8757f4@posting.google.com>

tiltonj@erols.com (Jay Tilton) wrote in message news:<3ddaed52.249498250@news.erols.com>...
> Simple algebra can eliminate a lot of the clutter.
> 
>     my $calc = (($percent)/$distribution)%@a;
>              = ((($score/$total_pts)*100)/(100/@a))%@a;
>              = ($score / $total_pts * @a) % @a;
> 
> The "%@a" part, besides having the appearance of a bizarre typo, is a
> do-nothing.  Assuming $score is always less than or equal to $total_pts,
> ($score / $total_pts * @a) can never be greater than scalar(@a).
> 
>     my $calc = $score / $total_pts * @a;


this is great! although since I am using the result to access @a it needs to be 
    my $calc = $score / $total_pts * (@a-1);
Thank you very much, I knew there was a lot of unnesesarry junk in there.

Mike Cardeiro


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

Date: Fri, 22 Nov 2002 02:06:25 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Format  a one line file to get two columns
Message-Id: <3DDD90E6.D0B91898@acm.org>

"David K. Wall" wrote:
> 
> Here's a longer way that that doesn't slurp the whole file.
> 
> Yeah, the OP said it was all on one line, but I was pleased with this idea.
> I'm sure it's much slower than your way (all that splitting, pushing, and
> shifting), but for a large file with lots of relatively short lines it uses
> less memory, right?

Ah, but if it _is_ all on one line then undefining $/ is redundant and
your method would read the whole file as well.


> ----------------------------
> use strict;
> use warnings;
> my @parts;
> while ( <DATA> ) {
>     push @parts, split;
>     print shift @parts, ' ', shift @parts, "\n" while (@parts >=2 );
> }
> # print any leftovers (in case the total number of parts is odd)
> print shift @parts, "\n" if @parts;
> 
> __DATA__
> -0.529766666666667 -8.89410873529075 -0.522816666666667
> -8.628319980362 0 0 4.9781502 12.02 5.0119999 12.05375
> 2.71828
> ----------------------------
> 
> I put that 2.71828 in there make the number of parts odd.  (e is a bit
> "odd", isn't it? :-)


This will only read blocks of 1K

#!/usr/bin/perl
use warnings;
use strict;

$/ = \1024;
while ( <> ) {
    s/\s+/--$| ? ' ' : "\n"/eg;
    s/\D*\z/\n/ if eof ARGV;
    print;
    }

__END__



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 21 Nov 2002 17:57:52 -0800
From: "Guoming Zhang" <guozhang@cisco.com>
Subject: how to split backslash
Message-Id: <1037930278.646436@sj-nntpcache-3>

Hi
I have one question. If  I have one string like the following:
my $string="PPPPP     \";
How can remove the last backslash, so that the string becomes

my string="PPPP"

thanks

gm




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

Date: Fri, 22 Nov 2002 02:05:50 GMT
From: Ian.H <ian@WINDOZEdigiserv.net>
Subject: Re: how to split backslash
Message-Id: <524rtugrh0mkn8sac9pk5nps1g0hiquvee@4ax.com>
Keywords: Remove WINDOZE to reply

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In a fit of excitement on Thu, 21 Nov 2002 17:57:52 -0800, "Guoming
Zhang" <guozhang@cisco.com> managed to scribble:

> Hi
> I have one question. If  I have one string like the following:
> my $string="PPPPP     \";
> How can remove the last backslash, so that the string becomes
> 
> my string="PPPP"
> 

The above example would fail, as  \" would be escaping the " but I'll
assume that it's read from somewhere and this isn't the issue.

Here's a quick script that appears to work:

#!d:/local/bin/perl -w

use strict;

my $string = "PPPPP     \\";
$string =~ s/(\s+)\\//g;

print $string;


HTH.


Regards,

  Ian

-----BEGIN xxx SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBPd2RSGfqtj251CDhEQLuUQCgphSbDiEFvUDCaIgXKFLk5ERVRd4AnRx5
jYAUg3f+hSJA/2lkNWLz5UD2
=t+6D
-----END PGP SIGNATURE-----

-- 
Ian.H  (Design & Development)
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.


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

Date: Fri, 22 Nov 2002 00:07:00 GMT
From: Keep it to Usenet please <idontreadthis56@hotmail.com>
Subject: List of all modules w/ versions
Message-Id: <idontreadthis56-B35729.18065921112002@netnews.attbi.com>

Is there a simple way to get a list of all the modules in @INC with 
their version numbers?

-- 
A: No.  See:                                                          Help, I'm
   <http://www.netmeister.org/news/learn2quote.html>                 being held
   <http://www.greenend.org.uk/rjk/2000/06/14/quoting>                in a .sig
Q: Should I include quotations after my reply?                         factory!


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

Date: Thu, 21 Nov 2002 19:27:55 -0500
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Re: List of all modules w/ versions
Message-Id: <arjtmm$s37@netnews.proxy.lucent.com>

"Keep it to Usenet please" <idontreadthis56@hotmail.com> wrote in
> Is there a simple way to get a list of all the modules in @INC with
> their version numbers?
1) download 'Inside' from cpan.
2) perldoc /your/perl/lib/$version/$architecture_number/perlocal.pod




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

Date: 22 Nov 2002 04:10:38 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: List of all modules w/ versions
Message-Id: <arkanu$d6d$1@canopus.cc.umanitoba.ca>

In article <arjtmm$s37@netnews.proxy.lucent.com>,
Tulan W. Hu <twhu@lucent.com> wrote:
:"Keep it to Usenet please" <idontreadthis56@hotmail.com> wrote in
:> Is there a simple way to get a list of all the modules in @INC with
:> their version numbers?
:1) download 'Inside' from cpan.

perl -MCPAN -e shell
cpan> i /inside/
CPAN: Storable loaded ok
Going to read /disk2/packages/perls/Metadata
  Database was generated on Thu, 21 Nov 2002 12:53:32 GMT
No objects found of any type for argument /inside/

cpan> i /Inside/
No objects found of any type for argument /Inside/


??
--
   Reviewers should be required to produce a certain number of
   negative reviews - like police given quotas for handing out
   speeding tickets.                        -- The Audio Anarchist


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

Date: Fri, 22 Nov 2002 03:17:36 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: Missing ..\Perl\lib\auto\Mail\Internet\autosplit.ix
Message-Id: <3DDDA20C.56EB7CC5@cox.net>

I am trying to use MIME::Parser in Win98SE in a script.
But I get an error 

"Cant' locate auto/Mail/Internet/autosplit.ix in @inc"
 at C:/../Perl/lib/Autoloader.pm line 146
 at C:/../Perl/lib/Mail/Internet.pm line 14

Execution is not aborted.

I cannot find auto/Mail/Internet/autosplit.ix anywhere on
http://www.activestate.com/ or on http://cpan.valueclick.com/modules/
or with Google-search. 

Fred


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

Date: Thu, 21 Nov 2002 19:33:48 -0500
From: "Ta Nea" <aaaaaaaaaaa@oh.org>
Subject: NYC
Message-Id: <OQeD9.2848$EY.175@fe01>

Hi,
If there is a Perl developer in the NYC area I need to speak with you for a
small project. Please respond here first and then we can exchange phone #s
etc.
AJ





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

Date: Fri, 22 Nov 2002 01:14:37 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: NYC
Message-Id: <1yfD9.47118$aB1.45247@nwrddc02.gnilink.net>

Ta Nea wrote:
> If there is a Perl developer in the NYC area [...]

Where did you see the "jobs.offered" in the title of this newsgroup?

jue




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

Date: 21 Nov 2002 15:37:22 -0800
From: manutd_kit@yahoo.com (kit)
Subject: Re: passing address between classes - OO type question
Message-Id: <1751b2b5.0211211537.7ffd3aea@posting.google.com>

Thank you very much for all the help. 
Actually, I have couple more questions, could you mind please help? 

1)----------
> Your definition of Kid->new() makes no use of its arguments,
> so why call it with arguments?

The reason why I call Kid->new() with arguments is trying to mimic the
idea of explicit constructor. If the call is like this,

   Kid->new($name); 

then, it could change the data member <name>. Is there any features in
perl to solve this problem?
 
2)---------- 
> You have a poor design. The kid's name is stored in two
> places, in the Kid object AND in Mum's kid{} hash.
>
> So you need to change it in both places.
 
Do you mean it could be better off if I can take away the <name>
datamember in the Kid object, and instead put it in the Mum's kid{}
hash?

3)----------
   Number of arguments for $self
   When we do,
     my ($self, $a) = @_;
   How many arguments can we have??

----------

Thanks for the help in advance. ;-)

Kit

----This is for your reference----Kid.pm----
package Kid;
use strict;
use warnings;

sub new {
	my $class = shift;
	my $self = {
		name => 'Kit',
		age => 20,
	};
	return bless $self, $class;
}
sub doHomeWork {
        my $self = shift;
	print "$self->{name} is doing homework.";
}
sub doDishes {
        my $self = shift;
	print "$self->{name} is doing dishes";
}
sub reName {
  my ($self, $newname) = @_;
  $self->{name} = $newname;
} 
sub printName {
  my $self = shift;
  print $self->{name};
}
1;
----Mum.pm----
package Mum;
use strict;
use warnings;
use Kid;

sub new {
        my $class = shift;
	my $self = {
		name => 'myMum',
		age => 40,
                kid => {},
	};
	return bless $self, $class;
}
sub giveBirth {
  my ($self, $name) = @_;
  ${$self->{kid}}{$name} = Kid->new();
  $self->{kid}{$name}->reName($name);
#  $self->{kid}{$name}->printName;
}
sub orderUp {
  my ($self, $kid) = @_;
  $self->{kid}{$kid}->doHomeWork;
#  $self->{kid}{}->doHomework;
}
1;
----driver.pl----
use strict;
use warnings;
use Mum;

my $aMother = Mum -> new();
$aMother -> giveBirth("perl");
$aMother -> orderUp("perl");
-----------------


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

Date: Thu, 21 Nov 2002 19:01:21 -0800
From: Dave E <fixerdave@hot-NoSpamPlease-mail.com>
Subject: Re: Perl one-liners in Win32
Message-Id: <3DDD9E00.3DA7B86E@hot-NoSpamPlease-mail.com>

> ... perl -le "print for map{glob}@ARGV" *.*

nifty, but how is a mere human suppose to know that:
    "-l[octal]       enable line ending processing, specifies line terminator"
means that each print statement gets put on a new line?  If I hadn't seen it here,
and experimented to see what it did, I'd have never understood what perl -h was
trying to tell me :)

Thanks for the tips, -l, qq, these things could come in handy.  As for the 'print
for' / 'statement if' syntax.  I'm starting to use it but it just seems weird.
Well, no, I take that back: it seems much more natural - almost English like - but
I'm still much too used to languages that force the reverse notation.  But then I
started way back when with BASIC (Sinclair ZX81 Basic to be precise :)  unless you
want to count a brief stint hand-compiling octal machine code...  I wonder if
they've ported Perl to the Sinclairs??  Then I don't suppose it could run with 1k
of RAM ;)

Thanks for the tips,

    David...

"John W. Krahn" wrote:

> Dave E wrote:
> >
> > Yes, now I get it!  I knew about the -n or -p switches but something in my
> > head just didn't make the connection between the filelist in @ARGV and the
> > loop.  I guess the begin thing threw me off.
> >
> > so, now:
> >     perl -e "BEGIN{@ARGV=map{glob}@ARGV}foreach (@ARGV) {print \"$_\n\"}" *.*
>
> Since you are not using -p or -n switch there is no need for the BEGIN
> block.  Also, you can use the qq operator to avoid backslashes.
>
>      perl -e "foreach (map{glob}@ARGV) {print qq($_\n)}" *.*
>
> OR
>
>      perl -le "print for map{glob}@ARGV" *.*
>
> John
> --
> use Perl;
> program
> fulfillment



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

Date: Thu, 21 Nov 2002 19:01:31 -0800
From: Dave E <fixerdave@hot-NoSpamPlease-mail.com>
Subject: Re: Perl one-liners in Win32
Message-Id: <3DDD9E0B.3BD13EF9@hot-NoSpamPlease-mail.com>

> ... it is wrapped in a BEGIN block, to make sure it is executed only
once...

So that's why it's there,

so I can do:
    perl -ne "BEGIN{print qq(print header once\n)}print qq($. $_)" test.txt
and get:
    print header once
    1 line a
    2 line b
    3 line c

(I like the qq thing from John too, thanks)

> ... \"$_\" is that reallly necessary?...

nope, I just started from a more complex example.  I cut things out until it
was barebones but didn't think to remove the quotes.  Like I said, I'm just
trying to learn what's going on with the one-liners with the assumption that,
one day, I'll need to do more than just print out the lines of a file :)

So how about I answer my own little quiz to see if I've got this right.  With
the line:
    perl -ne "BEGIN{@ARGV=map{glob}@ARGV}/string_to_find/&&print $_" *.*
Perl pulls this in and the first thing it does is put the rest of the
parameters after the -e string into the ARGV array.  Then it processes the
begin block.  This takes the *.* text string in the first of  @$ARGV (I
assume it would process more if there were additional parameters) and uses
map{glob} to convert it to an array of filenames that it puts back into
@ARGV.  Then it passes this array to the <> loop, doing everything after the
begin block for each line.  For each line, if the regular expression is true,
the second part of the AND statment runs, in this case just printing the
line.

So how am I doing?

    David...

Bart Lateur wrote:

> Dave E wrote:
>
> >Of course, I found this one:
> >    perl -ne "BEGIN{@ARGV=map{glob}@ARGV}/string_to_find/&&print\"$_\""
> >*.*
> >which searches for a string in the files specified by the wildcards -
> >very useful, but I still can't figure out how it loops through each line
> >of every file :)
>
> You got the reason for the loop from Tad. So I won't go into that.
>
> That BEGIN block is necessary because the Windows shell doesn't do any
> file globbing by itself. So if you pass "*.txt" as a command line
> argument, there will be a bare string "*.txt" in one of the array items
> in @ARGV.
>
> Because of the implicit loop, it is wrapped in a BEGIN block, to make
> sure it is executed only once, before the loop starts.
>
> And that print \"$_\" is that reallly necessary? Does it do anything a
> bare print won't do?
>
> --
>         Bart.



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

Date: Thu, 21 Nov 2002 19:05:10 -0800
From: Dave E <fixerdave@hot-NoSpamPlease-mail.com>
Subject: Re: Perl one-liners in Win32
Message-Id: <3DDD9EE6.EA0C05D7@hot-NoSpamPlease-mail.com>

opps, @$ARGV was a typo, not that it matters, just heading of unnecessary
replies.

    David...

Dave E wrote:

> > ... it is wrapped in a BEGIN block, to make sure it is executed only
> once...
>
> So that's why it's there,
>
> so I can do:
>     perl -ne "BEGIN{print qq(print header once\n)}print qq($. $_)" test.txt
> and get:
>     print header once
>     1 line a
>     2 line b
>     3 line c
>
> (I like the qq thing from John too, thanks)
>
> > ... \"$_\" is that reallly necessary?...
>
> nope, I just started from a more complex example.  I cut things out until it
> was barebones but didn't think to remove the quotes.  Like I said, I'm just
> trying to learn what's going on with the one-liners with the assumption that,
> one day, I'll need to do more than just print out the lines of a file :)
>
> So how about I answer my own little quiz to see if I've got this right.  With
> the line:
>     perl -ne "BEGIN{@ARGV=map{glob}@ARGV}/string_to_find/&&print $_" *.*
> Perl pulls this in and the first thing it does is put the rest of the
> parameters after the -e string into the ARGV array.  Then it processes the
> begin block.  This takes the *.* text string in the first of  @$ARGV (I
> assume it would process more if there were additional parameters) and uses
> map{glob} to convert it to an array of filenames that it puts back into
> @ARGV.  Then it passes this array to the <> loop, doing everything after the
> begin block for each line.  For each line, if the regular expression is true,
> the second part of the AND statment runs, in this case just printing the
> line.
>
> So how am I doing?
>
>     David...
>
> Bart Lateur wrote:
>
> > Dave E wrote:
> >
> > >Of course, I found this one:
> > >    perl -ne "BEGIN{@ARGV=map{glob}@ARGV}/string_to_find/&&print\"$_\""
> > >*.*
> > >which searches for a string in the files specified by the wildcards -
> > >very useful, but I still can't figure out how it loops through each line
> > >of every file :)
> >
> > You got the reason for the loop from Tad. So I won't go into that.
> >
> > That BEGIN block is necessary because the Windows shell doesn't do any
> > file globbing by itself. So if you pass "*.txt" as a command line
> > argument, there will be a bare string "*.txt" in one of the array items
> > in @ARGV.
> >
> > Because of the implicit loop, it is wrapped in a BEGIN block, to make
> > sure it is executed only once, before the loop starts.
> >
> > And that print \"$_\" is that reallly necessary? Does it do anything a
> > bare print won't do?
> >
> > --
> >         Bart.



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

Date: Thu, 21 Nov 2002 19:22:03 -0600
From: Lance Hoffmeyer <lance@augustmail.com>
Subject: Re: regex subroutine \) passing variables SOLVED
Message-Id: <pan.2002.11.22.01.22.00.867348.27400@augustmail.com>

Use of the \Q .. \E

On Thu, 21 Nov 2002 10:52:07 -0600, Lance Hoffmeyer wrote:

> I keep trying to run this subroutine. It keeps bombing out on the second
> item
> 
> "\(\+5\) VERY"
> 
> Quantifier follows nothing before HERE 2 (+ <<HERE if I remove the "+" I
> get error
> Unmatched ( before HERE   ( <<HERE
> 
> 
> So, I guess my slashs are not being passed and a \+ is being interpreted
> as a + and a \( is being interpreted as a (.
> 
> How do I correct this?
> 
> sub find_num{
> ##############################
> #Subroutine to find numbers
> #The following variables are needed
> # TABLE   = 82;                                        # Table number to
> look for # ROWTEXT = "YES, AWARE OF KEEP";                      # Row text
> (Should be row with freqs not percents) # COLUMN  = "N";         
> XT,COLUMN)
> ##############################
> my $colnum = column2column_number($_[2]); $file =~
> /TABLE\s*$_[0].*?$\Q_[1]\E.*?(?:(\d{1,2}\.\d)\D+){$colnum}/s; return my $num =
> $1;
> }
> }
> 
> 
> my $var = find_num(103,"\(\+5\) VERY","H");$var = Round($var,0);
	


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

Date: Thu, 21 Nov 2002 19:32:26 -0600
From: Lance Hoffmeyer <lance@augustmail.com>
Subject: regexp help
Message-Id: <pan.2002.11.22.01.32.26.198646.29313@augustmail.com>

My question concerns the part ?:(\d{1,2}\.\d)\D+{$colnum}


I need to incorporate an "or" in this so that this part can be
\d\d.\d or "-" (a dash). followed by any non-numeric data

Lance




my $colnum = column2column_number($_[2]); $file =~
 /TABLE\s*$_[0].*?$\Q_[1]\E.*?(?:(\d{1,2}\.\d)\D+){$colnum}/s;



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

Date: Fri, 22 Nov 2002 04:50:36 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: regexp help
Message-Id: <wIiD9.4656$op6.3890@news4.srv.hcvlny.cv.net>


"Lance Hoffmeyer" <lance@augustmail.com> wrote in message
news:pan.2002.11.22.01.32.26.198646.29313@augustmail.com...
> My question concerns the part ?:(\d{1,2}\.\d)\D+{$colnum}

Part of what?

>
>
> I need to incorporate an "or" in this so that this part can be

this?

> \d\d.\d or "-" (a dash). followed by any non-numeric data
--snip--

I have to make several assumptions.  Correct me if I am wrong.

?: some how makes sense, but is not relevant to the question

The first character of $column is a digit not relevant to the question.

Data between the colon and the first digit of $column conforms to one of two
formats.
  12.3xx
     or
  -abc

I am free to add capturing parens.  I could use the non-capturing kind, but
normal ones are easier to read.

White space, if any, before the first digit of $column is significant in
both cases.  It is captured by the \D.

Ok? Try this

?:((\d{1,2}\.\d)\D+)|(-\D+)){$colnum}  #(untested)

Bill






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

Date: Fri, 22 Nov 2002 03:45:39 GMT
From: "News" <tjalbout@hotmail.com>
Subject: shtml and Perl
Message-Id: <DLhD9.1421$ea.73627@news2.calgary.shaw.ca>

Got a question, I have a perl script that calls a shtml file.
In the shtml file I have a "<!--#include virtual= "  function. If I run the
shtml file by itself, it works fine but if I run it through the perl script,
the include doesn't work.
Any ideas? Am I missing a server config?

Thanks!
-T




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

Date: Fri, 22 Nov 2002 01:31:08 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Why can't code print an @array??
Message-Id: <MPG.1847369e10fc1d5b9898e6@news.edmonton.telusplanet.net>

In article <slrnatouu2.1l5.tadmc@magna.augustmail.com>, 
tadmc@augustmail.com says...

[ some snipped ]

> Try this one instead:
> 
>     print "@stack[0..3]\n";
> 
> Viola! No warnings.
> 
> 
> Wanna know which elements are undef? Just ask perl:
> 
>    foreach ( 0..$#stack ) {
>       print "index $_ is uninitialized\n" unless defined $stack[$_];
>    }
> 
> 
> > So why doesn't the above print "@stack\n" work the same way???
> 
> 
> It does work the same way.
> 
> What makes you think it doesn't?

Thanks Tad.  I can see that I was wrongly assuming that an assignment 
from the caller array to the @stack array by the following type of 
line...

@stack = caller(1);

was the same as...

($pack, $file, $line, $sub) = caller(1);

I see now that they are not.  The former sticks into @stack all the 
values returned by caller() - some of which are undefined - while the 
latter only picks up the first four.  Thus the undefined values error 
whey I try to print @stack.  

I'll have to carefully watch my assumptions in the future.  Line by line.  

I only hope that I can someday see things as intuitively as you all seem 
to do.  I suppose that comes from writing thousands of lines of code.  
Something I have not yet done.  Since I put a lot of my code in modules, 
once I figure out how to do something, I don't get much practice in the 
fundamentals.  Instead I tend to forget what I learned in writing the 
module code, however complicated it may be, since I don't have to concern 
myself with the details of it's internal Perl code anymore.  I just call 
the easy interface.  This has it's definite advantages but it also keeps 
me from practicing Perl.  

Thanks again to you and everyone else who responded.  I appreciate it!

-- 
Carlos 
www.internetsuccess.ca/best_web_hosting.html


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

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.  

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 4158
***************************************


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