[24230] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6422 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 19 15:03:15 2004

Date: Mon, 19 Apr 2004 12:01:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 19 Apr 2004     Volume: 10 Number: 6422

Today's topics:
    Re: Problems using regexp with cygwin diff on Windows 2 <invalid-email@rochester.rr.com>
    Re: Problems using regexp with cygwin diff on Windows 2 <mailing-list@gheift.de>
    Re: Problems using regexp with cygwin diff on Windows 2 (Joerg Moeller)
    Re: Problems using regexp with cygwin diff on Windows 2 (Joerg Moeller)
        Problems with MS Telnet Server (Mike)
    Re: Problems with MS Telnet Server <nospam@bigpond.com>
        Processing Very Large Files <budman@somewhere.net>
    Re: Processing Very Large Files <snowhare@nihongo.org>
    Re: Processing Very Large Files ctcgag@hotmail.com
    Re: Processing Very Large Files <budman@somewhere.net>
    Re: Processing Very Large Files <budman@somewhere.net>
    Re: Processing Very Large Files <glex_nospam@qwest.invalid>
    Re: Processing Very Large Files <nobull@mail.com>
        question about keeping space with split (Brian)
    Re: question about keeping space with split <krahnj@acm.org>
    Re: question about keeping space with split <tadmc@augustmail.com>
    Re: question about substr <somebody@nowhere.com>
    Re: Reading input from files and directories in the com <a24061@yahoo.munged>
    Re: recording votes <robin @ infusedlight.net>
        regex compression? (Bill)
    Re: regex compression? <nobull@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 17 Apr 2004 01:13:32 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Problems using regexp with cygwin diff on Windows 2000
Message-Id: <408080E3.8030206@rochester.rr.com>

Joerg Moeller wrote:

 ...
> Example:
> 
> diff -I '^\s*VERSION' aCMNdiskDriveController.contrib1
> aCMNdiskDriveController.base
> 
> works fine but the regular expression is incomplete. A more complete
> expression would be
> 
> C:\cygwin\bin>diff -I '^\s*VERSION [\w\d\\_\.\']*'
> aCMNdiskDriveController.contrib1 aCMNdiskDriveController.base
> 
> What give the following error:
> diff: missing operand after `\s*VERSION [\w\d\_\.']*
> aCMNdiskDriveController.contrib1 aCMNdiskDriveController.base'
> diff: Try `diff --help' for more information.
> 
> Anybody an idea what's wrong or how to work around this problem? 
 ...
> Joerg
> 


What shell are you running?  bash?  If so, did you read in the man page 
where it says:


"A  single quote  may not occur between single quotes, even when pre-
  ceded by a backslash."

You will thus need to use an appropriate quoting mechanism for putting 
the apostrophe into your regexp.  Maybe something like [untested]:

diff -I '^\s*VERSION [\w\d\\_\.\'"'"']*' file1 file2

And yes, you're way off-topic for this newsgroup :-)
-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sat, 17 Apr 2004 15:19:48 +0200
From: Gerhard Heift <mailing-list@gheift.de>
Subject: Re: Problems using regexp with cygwin diff on Windows 2000
Message-Id: <c5rao1$qk1$1@online.de>

Joerg Moeller wrote:
> Example:
> 
> diff -I '^\s*VERSION' aCMNdiskDriveController.contrib1
> aCMNdiskDriveController.base
> 
> works fine but the regular expression is incomplete. A more complete
> expression would be
> 
> C:\cygwin\bin>diff -I '^\s*VERSION [\w\d\\_\.\']*'
> aCMNdiskDriveController.contrib1 aCMNdiskDriveController.base
> 
> What give the following error:
> diff: missing operand after `\s*VERSION [\w\d\_\.']*
> aCMNdiskDriveController.contrib1 aCMNdiskDriveController.base'
> diff: Try `diff --help' for more information.
> 
> Anybody an idea what's wrong or how to work around this problem? 

Untestet:

C:\cygwin\bin>diff -I "^\s*VERSION [\w\d\\_\.\']*"

With doublequotes ("), not singel-ones (').

Pherhaps it works...

Gerhard


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

Date: 19 Apr 2004 00:47:58 -0700
From: joergmoellernexpress@hotmail.com (Joerg Moeller)
Subject: Re: Problems using regexp with cygwin diff on Windows 2000
Message-Id: <caf034b4.0404182347.135c9c4@posting.google.com>

Bob Walton <invalid-email@rochester.rr.com> wrote in message news:<408080E3.8030206@rochester.rr.com>...
> Joerg Moeller wrote:
> 
> ...
> > Example:
> > 
> > diff -I '^\s*VERSION' aCMNdiskDriveController.contrib1
> > aCMNdiskDriveController.base
> > 
> > works fine but the regular expression is incomplete. A more complete
> > expression would be
> > 
> > C:\cygwin\bin>diff -I '^\s*VERSION [\w\d\\_\.\']*'
> > aCMNdiskDriveController.contrib1 aCMNdiskDriveController.base
> > 
> > What give the following error:
> > diff: missing operand after `\s*VERSION [\w\d\_\.']*
> > aCMNdiskDriveController.contrib1 aCMNdiskDriveController.base'
> > diff: Try `diff --help' for more information.
> > 
> > Anybody an idea what's wrong or how to work around this problem? 
>  ...
> > Joerg
> > 
> 
> 
> What shell are you running?  bash?  If so, did you read in the man page 
> where it says:

Not using bash, just simple plain MS-DOS Shell.

> 
> 
> "A  single quote  may not occur between single quotes, even when pre-
>   ceded by a backslash."
> 
> You will thus need to use an appropriate quoting mechanism for putting 
> the apostrophe into your regexp.  Maybe something like [untested]:
> 
> diff -I '^\s*VERSION [\w\d\\_\.\'"'"']*' file1 file2

This seems to make the trick ;-) unfortunately if I'm expanding the
repexp it doesn't match any longer. The line to be matched is
something like:

VERSION 'kiel_int_v3.6.x\dev_v3.6.8_ellerbrock_01\2' LIBRARY
'z:\CMN\objectime.otlib'

And 

diff -I '^\s*VERSION [\w\d\\_\.\'"'"']*' file1 file2

works and ignores this line but

diff -I '^\s*VERSION [\w\d\\_\.\'"'"']*?\s* LIBRARY' file1 file2

doesn't work and display the line as difference.

> 
> And yes, you're way off-topic for this newsgroup :-)

I'm aware of it. But any other idea where to post this? I'm really
beeing desperate and was quite unsure if I should post it here ;-)

Many thanks for your help.

regards
Joerg


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

Date: 19 Apr 2004 00:49:10 -0700
From: joergmoellernexpress@hotmail.com (Joerg Moeller)
Subject: Re: Problems using regexp with cygwin diff on Windows 2000
Message-Id: <caf034b4.0404182349.49047f09@posting.google.com>

Gerhard Heift <mailing-list@gheift.de> wrote in message news:<c5rao1$qk1$1@online.de>...
> Joerg Moeller wrote:
> > Example:
> > 
> > diff -I '^\s*VERSION' aCMNdiskDriveController.contrib1
> > aCMNdiskDriveController.base
> > 
> > works fine but the regular expression is incomplete. A more complete
> > expression would be
> > 
> > C:\cygwin\bin>diff -I '^\s*VERSION [\w\d\\_\.\']*'
> > aCMNdiskDriveController.contrib1 aCMNdiskDriveController.base
> > 
> > What give the following error:
> > diff: missing operand after `\s*VERSION [\w\d\_\.']*
> > aCMNdiskDriveController.contrib1 aCMNdiskDriveController.base'
> > diff: Try `diff --help' for more information.
> > 
> > Anybody an idea what's wrong or how to work around this problem? 
> 
> Untestet:
> 
> C:\cygwin\bin>diff -I "^\s*VERSION [\w\d\\_\.\']*"
> 
> With doublequotes ("), not singel-ones (').
> 
> Pherhaps it works...
> 
> Gerhard

Gerhard,

already tried it. Doesn't work ;-) Thank you for your help anyway.

regards
Joerg


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

Date: 19 Apr 2004 08:51:56 -0700
From: miketaylorsf@yahoo.com (Mike)
Subject: Problems with MS Telnet Server
Message-Id: <411fc73f.0404190751.1beb6a33@posting.google.com>

I am trying to telnet to a Windows 2K server, running the MS Services
for Unix Telnet Server.

I can connect to the box and my commands execute correctly, but I am
unable to gather the results of the commands I run.  I have seen
postings online saying that the MS Telnet Server is not a "real"
telnet server and the fix for this problem is to install another
telnet server.  This is not an option for me.  I am stuck with this
server, and can't change it.

Can anybody help? 

Here is my code. The output array is always empty, but I know the
command ran correctly.  If I put the telnet module into debug and then
read the debug log, I can see the data being transfered back to my PC,
but it never gets put into the @output array.  I think it has
something to do with the value of $prompt, but I have tried multiple
different ways and nothing seems to work:

##############################################################
use strict;
use Net::Telnet;

my $prompt = '/>/'; 

my $host = "192.168.5.2";
my $user = "user";
my $pass = "password";
my $session = Net::Telnet->new( Timeout => 30,
   Prompt  => $prompt,
   Host    => $host );
$session->login($user, $pass);

my $command = 'dumpel -l system -t';     

print "About to Execute $command\n";

my @output = $session->cmd(     String => $command,
   Prompt => $prompt);

sleep 10;
$session->close;

print @output;
exit;


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

Date: Tue, 20 Apr 2004 03:01:49 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Problems with MS Telnet Server
Message-Id: <1667518.ObsSn87WcO@GMT-hosting-and-pickle-farming>

Mike wrote:

> I am trying to telnet to a Windows 2K server, running the MS Services
> for Unix Telnet Server.
> 
> I can connect to the box and my commands execute correctly, but I am
> unable to gather the results of the commands I run.  I have seen
> postings online saying that the MS Telnet Server is not a "real"
> telnet server and the fix for this problem is to install another
> telnet server.  This is not an option for me.  I am stuck with this
> server, and can't change it.
> 
> Can anybody help?

Try expect(1) instead of Perl.

gtoomey


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

Date: Sat, 17 Apr 2004 12:05:56 -0300
From: budman <budman@somewhere.net>
Subject: Processing Very Large Files
Message-Id: <pan.2004.04.17.15.05.54.459502@somewhere.net>

Hi,

I recently ran into an issue when processing a 4.5GB tab delimited file
with perl.

I would get the structure from a database table to use for comparison.
The program was a standard cleanup script.
  - check field count per row
  - check for nulls where nulls were not allowed
  - check each character field length 
  - create a clean file and an error file

When I ran the script on smaller 2GB files, it ran okay, but slow.
At the time, I only used it as a tool to help troubleshoot bad BCP files.

Then I needed to apply it to production. :) 

Well.. this is where I saw it stressed to the max.
Processing a 4GB file, perl was only processing about 8MB/min.
This was taking over 3 hours.

Its a very basic procedure: (dont have the code its at work)
	open
	while
	   reset error var
	   split the line by tab
	   check the field count
	   if nulls not allowed in table, check the fields that are not 
              allowed to have null
	   check each char field length
	   if errors write to errlog otherwise write to cleanfile.
	close

So then I ran awk with the same tests:
  awk with same checks writing only a clean file - 110MB/min
	  4GB took 36 min.
  awk with compares and writing both files - 80MB/min
	  4GB takes a little under an hour.

The awk code looks like:
awk 'BEGIN{FS="\t"}{if(NF==10 && length($1)<=11 && length($2)<=8) \
{print >"cleanfile"}else{printf"Line %%s: %%s\n",NR,$0 >"errlog"}}' \
HugeFile

The approach I took was using perl to retrieve the database table info,
and then assemble an awk statement that compares each field size,
and checks for nulls.  In all about 15 compares in total.  It still gets
about 90MB/min.

I don't mind the result since it gets the job done.
I was just curious if there was a way to get perl to have similar results
as in awk.

Thanks,
Rich



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

Date: Sun, 18 Apr 2004 15:37:42 GMT
From: Benjamin Franz <snowhare@nihongo.org>
Subject: Re: Processing Very Large Files
Message-Id: <Xns94CF57D6A1D60snowharenihongoorg@64.164.98.50>

budman <budman@somewhere.net> wrote in 
news:pan.2004.04.17.15.05.54.459502@somewhere.net:


> Then I needed to apply it to production. :) 
> 
> Well.. this is where I saw it stressed to the max.
> Processing a 4GB file, perl was only processing about 8MB/min.
> This was taking over 3 hours.
> 
> Its a very basic procedure: (dont have the code its at work)
>      open
>      while
>         reset error var
>         split the line by tab
>         check the field count
>         if nulls not allowed in table, check the fields that are not 
>               allowed to have null
>         check each char field length
>         if errors write to errlog otherwise write to cleanfile.
>      close

To much stuff in the time critical loop. Also - did you open the errlog 
and clean file _before_ entering the loop? Opening and closing then 
repeatedly would be a significant performance hit. I would code it 
something like this:

my $validation_regex = qr/$assembled_validation_string/;
open(INPUT_FILE,$input_filename)
       || die ("Couldn't open $input_filename: !$\n");
open(ERROR_FILE,">>$error_log_filename")
       || die ("Couldn't open $error_log_filename: $!\n");
open(CLEAN_FILE,">$output_filename")
       || die ("Couldn't open $output_filename: $!\n");
while(<INPUT_FILE>) {
    if (m/$validation_regex/) {
        print CLEAN_FILE;
    } else {
        print ERROR_FILE;
    }
}
close(CLEAN_FILE);
close(ERROR_FILE);
close(INPUT_FILE);

Unless you have wierd (read 'extremely CPU expensive') validation 
patterns, it should approach the I/O limitted speed for your system.

-- 
Benjamin Franz


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

Date: 19 Apr 2004 02:40:16 GMT
From: ctcgag@hotmail.com
Subject: Re: Processing Very Large Files
Message-Id: <20040418224016.152$wW@newsreader.com>

budman <budman@somewhere.net> wrote:
>
> Well.. this is where I saw it stressed to the max.
> Processing a 4GB file, perl was only processing about 8MB/min.
> This was taking over 3 hours.

Does the time taken scale linearly with size of input?  If not,
I suspect that you are leaking something somewhere.

>
> Its a very basic procedure: (dont have the code its at work)

That really limits the type of advice we can give.

Xho

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


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

Date: Mon, 19 Apr 2004 08:56:04 -0300
From: budman <budman@somewhere.net>
Subject: Re: Processing Very Large Files
Message-Id: <pan.2004.04.19.11.56.02.350893@somewhere.net>

On Sun, 18 Apr 2004 15:37:42 +0000, Benjamin Franz wrote:

> budman <budman@somewhere.net> wrote in 
> news:pan.2004.04.17.15.05.54.459502@somewhere.net:
> 
> 
>> Then I needed to apply it to production. :) 
>> 
>> Well.. this is where I saw it stressed to the max.
>> Processing a 4GB file, perl was only processing about 8MB/min.
>> This was taking over 3 hours.
>> 
>> Its a very basic procedure: (dont have the code its at work)
>>      open
>>      while
>>         reset error var
>>         split the line by tab
>>         check the field count
>>         if nulls not allowed in table, check the fields that are not 
>>               allowed to have null
>>         check each char field length
>>         if errors write to errlog otherwise write to cleanfile.
>>      close
> 
> To much stuff in the time critical loop. Also - did you open the errlog 
> and clean file _before_ entering the loop? Opening and closing then 
> repeatedly would be a significant performance hit. I would code it 
> something like this:
> 
> my $validation_regex = qr/$assembled_validation_string/;

This is a good idea.  Forgot about caching the regex. :)

What you have below, is exactly what I used, except the testing was
different.

> open(INPUT_FILE,$input_filename)
>        || die ("Couldn't open $input_filename: !$\n");
> open(ERROR_FILE,">>$error_log_filename")
>        || die ("Couldn't open $error_log_filename: $!\n");
> open(CLEAN_FILE,">$output_filename")
>        || die ("Couldn't open $output_filename: $!\n");
> while(<INPUT_FILE>) {
>     if (m/$validation_regex/) {
>         print CLEAN_FILE;
>     } else {
>         print ERROR_FILE;
>     }
>     }
> close(CLEAN_FILE);
> close(ERROR_FILE);
> close(INPUT_FILE);
> 
> Unless you have wierd (read 'extremely CPU expensive') validation
> patterns, it should approach the I/O limitted speed for your system.

The while loop consisted of:

	# need to remove newline on last field for size check
	chomp( $line = $_ );

	(@x) = split /\t/,$line;

	$error = 0;

	# Check Total Fields in row
        if ( scalar(@x) != $total_fields ) {  
	   print ERRORLOG "FieldCount: $line\n";
	   $error++;
	}
	next if $error;
	# Check Null Allowed Fields (if any)
	foreach $field ( @NullFields ) {
	   if ( length( $x[$field] ) == 0 ) { 
               print ERRORLOG "Nulls: $line\n"; 
	       $error++;
	       last;
           }	
	}
 	next if $error;
	# Check Char Fields if size exceeds limit
	foreach $field ( @CharFields ) {
           if ( length( $x[$field] ) > $FieldSize[$field] ) {
               print ERRORLOG "FieldSize: $line\n";
	       $error++;
	       last;
	   }
	}
	next if $error;
	print CLEANFILE;

Thats what I can recall for the most part.
I have the two arrays, because sometimes there may be only 2 fields that
have nulls not allowed, a few less compares- if there are 10 fields,
checking on 2 saves 8 checks per row.  Had somewhat better results than
checking all the fields.

I think the NullFields has maybe 4 items, CharFields has maybe 6.
I removed the numeric fields in the size test, saved some more compares.

Can it be optimized further?

Thanks for your suggestions.
Rich

		


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

Date: Mon, 19 Apr 2004 09:09:51 -0300
From: budman <budman@somewhere.net>
Subject: Re: Processing Very Large Files
Message-Id: <pan.2004.04.19.12.09.50.177037@somewhere.net>

On Mon, 19 Apr 2004 02:40:16 +0000, ctcgag wrote:

> budman <budman@somewhere.net> wrote:
>>
>> Well.. this is where I saw it stressed to the max.
>> Processing a 4GB file, perl was only processing about 8MB/min.
>> This was taking over 3 hours.
> 
> Does the time taken scale linearly with size of input?  If not,
> I suspect that you are leaking something somewhere.
> 

Yes. I was able to calculate the times and it finished very close to
what I computed.

I noticed files smaller than 2GB seem to process faster.
When it goes over 2GB, thats when I see it start to slow down.
I'll see if I can run some tests on different size files to
get an idea.  I was thinking it may be system related given
some past problems when files reached 2GB or even 4GB.

Before this cleaner script, there was not way to edit the file.
No editor would work.  They all crapped out at 1GB.
The only way was to split the file in 50MB chunks and try to figure
out the bad files - usually by an account id.  Then edit the 
split files and cat them back together.  It worked, but very
time consuming.  Not the kind of thing you want to do with other
jobs in the stream needing attention. 

>>
>> Its a very basic procedure: (dont have the code its at work)
> 
> That really limits the type of advice we can give.
>
Thanks.  I did an exhaustive web search and found hardly anything
that helped.  So I tried optimizing my code more and more.

Each Row had at max 13 compares. 
Actually before I build the commands for awk, I built the whole
compare statement in 1 line and evaled it.  This worked, but it
showed very little speed improvment.  So now the rows were down
to one eval statement and one test if the eval failed write to
error or clean.  

I get a copy of my code to post.

Thanks,
Rich

 
> Xho




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

Date: Mon, 19 Apr 2004 12:08:11 -0500
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: Processing Very Large Files
Message-Id: <0ITgc.35$GR2.48441@news.uswest.net>

budman wrote:

> The while loop consisted of:
> 
> 	# need to remove newline on last field for size check
> 	chomp( $line = $_ );
> 
> 	(@x) = split /\t/,$line;
[...]
> Can it be optimized further?

If that's really your code..

use strict;

That should improve your and help you catch problems like the above 
being in a loop.  Hint: make @x a lexical.


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

Date: 19 Apr 2004 18:20:02 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Processing Very Large Files
Message-Id: <u93c6z3mwt.fsf@wcl-l.bham.ac.uk>

budman <budman@somewhere.net> writes:

> 	# need to remove newline on last field for size check
> 	chomp( $line = $_ );
> 
> 	(@x) = split /\t/,$line;
> 
> 	$error = 0;
> 
> 	# Check Total Fields in row
>         if ( scalar(@x) != $total_fields ) {  
> 	   print ERRORLOG "FieldCount: $line\n";
> 	   $error++;
> 	}
> 	next if $error;
> 	# Check Null Allowed Fields (if any)
> 	foreach $field ( @NullFields ) {
> 	   if ( length( $x[$field] ) == 0 ) { 
>                print ERRORLOG "Nulls: $line\n"; 
> 	       $error++;
> 	       last;
>            }	
> 	}
>  	next if $error;
> 	# Check Char Fields if size exceeds limit
> 	foreach $field ( @CharFields ) {
>            if ( length( $x[$field] ) > $FieldSize[$field] ) {
>                print ERRORLOG "FieldSize: $line\n";
> 	       $error++;
> 	       last;
> 	   }
> 	}
> 	next if $error;
> 	print CLEANFILE;
> 
> Thats what I can recall for the most part.

Have you read the posting guidelines.  You should not retype code.

> I have the two arrays, because sometimes there may be only 2 fields that
> have nulls not allowed, a few less compares- if there are 10 fields,
> checking on 2 saves 8 checks per row.  Had somewhat better results than
> checking all the fields.
> 
> I think the NullFields has maybe 4 items, CharFields has maybe 6.
> I removed the numeric fields in the size test, saved some more compares.
> 
> Can it be optimized further?

You can use a labeled next and get rid of the variable $error.

The if (length() == 0) is more simply unless(length(...))

You can use a slice rather than an index loop in the nulls check but I
can't say for for certain it is going to be any faster without
benchmarking.  Similarly using $_ rather than a named loop variable
may give some speed gain (but then again it may not and some people
just think it's altogether ugly).

   foreach ( @x[@NullFields] ) {
     unless ( length ) { 
       print ERRORLOG "Nulls: $line\n"; 
       next OUTER_LOOP;
     }
   }

You should always declare all variables as lexically scoped in the
smallest applicable lexical scope unless you have a positive is a
reason to do otherwise. BTW: this is not perculliar to Perl, it
applies in all programming languges - allowing that a languge not
having lexical variables is a positive reason :-).

For Perl this means that most of the time the declaration should be
combined with the first assignment. BTW: this to is not perculliar to
Perl, it also applies in other programming languges where assignment
and declaration can be combined.

By following this convention you will be able to get maximum beniefit
out of putting "use strict" at the top of all your scripts.

Try to get into this habit now, do not wait for your failure to do so
to cause you the unecessary distress of wasting your own time and that
of other people.  The longer you leave it the harder you will find it
to adjust.  Worse still, if you leave it too long you may never adjust
and may mutate into a bitter and twisted troll.

That said, using lexical variables will only give you a tiny
perfomance gain.  The main gain is in maintainability.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 16 Apr 2004 23:48:23 -0700
From: leetiger_cn@hotmail.com (Brian)
Subject: question about keeping space with split
Message-Id: <b5e6fb4e.0404162248.33cd5e04@posting.google.com>

Hello everyone,
Here I have a question

I use split to deal with the following data   60,,,74,0,,62,0,,42 
some spaces exist between commas.

while (<INPUT>)
{
  chomp;
  my @array = split/,/;
}

In the @array the spaces between two comma change to 0. But I still
want to save the space distintively in the array other than a 0,
because I want to do some operation on the space in the @array late.
For instance
if ($fields[$num]== space ){
	   $fields[$num]=100;
}

Could someone help me about it?  Thanks alot.
Brian


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

Date: Sat, 17 Apr 2004 07:48:37 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: question about keeping space with split
Message-Id: <4080E149.6AC36768@acm.org>

Brian wrote:
> 
> Here I have a question
> 
> I use split to deal with the following data   60,,,74,0,,62,0,,42
> some spaces exist between commas.
> 
> while (<INPUT>)
> {
>   chomp;
>   my @array = split/,/;
> }
> 
> In the @array the spaces between two comma change to 0.

perl doesn't do that so you must be doing it yourself.

> But I still
> want to save the space distintively in the array other than a 0,
> because I want to do some operation on the space in the @array late.

Your example doesn't have spaces between the commas.  Two commas next to
each other would result in a zero-length string.  If you use a
non-numeric string in a numerical expression it will be evaluated as 0.

> For instance
> if ($fields[$num]== space ){
                   ^^^^^^^^
You probably meant:

if ($fields[$num] eq '' ){

You can't compare strings with numerical comparison operators.

>            $fields[$num]=100;
> }


John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 17 Apr 2004 10:33:02 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: question about keeping space with split
Message-Id: <slrnc82jhe.kg2.tadmc@magna.augustmail.com>

Brian <leetiger_cn@hotmail.com> wrote:

> I use split to deal with the following data   60,,,74,0,,62,0,,42 
> some spaces exist between commas.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Then you should show data that has some spaces between commas.

There are no spaces between commas in the data you've shown.


> while (<INPUT>)
> {
>   chomp;
>   my @array = split/,/;
> }
> 
> In the @array the spaces between two comma change to 0. 


No they don't.


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

while (<DATA>)
{
  chomp;
  my @array = split/,/;

  print "[$_]\n" for @array;
}

__DATA__
60,,,74,0,,62,0,,42
-------------------------------

output:
[60]
[]
[]
[74]
[0]
[]
[62]
[0]
[]
[42]


> But I still
> want to save the space distintively in the array other than a 0,


There are neither spaces nor "added" zeros in any of the fields.


> Could someone help me about it? 


Help you with what?

As far as we can see the problem you describe does not exist.

If we could duplicate the problem we could help solve the problem.

But we can't, so we can't.


Post a short and complete program that we can run that illustrates
your problem, and we will help you fix the problem.

Have you seen the Posting Guidelines that are posted here frequently?


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


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

Date: Fri, 16 Apr 2004 21:30:47 -0000
From: "Pope Bob" <somebody@nowhere.com>
Subject: Re: question about substr
Message-Id: <40805054.54c.41@news2>

>
> RTFM.

Considering your past postings and demonstrated level of
competence, your
attitude is incredible.

Just shut up and go away.  Now.


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

Date: Mon, 19 Apr 2004 09:42:10 GMT
From: Adam <a24061@yahoo.munged>
Subject: Re: Reading input from files and directories in the command line arguments (like grep -R).
Message-Id: <S9Ngc.2734$bm6.26392712@news-text.cableinet.net>

On Tuesday 13 April 2004 16:49, Paul Lalli wrote:

> Use the standard File::Find module:

Excellent, thanks!  (I don't know how I missed that when searching for a
way to do it.)



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

Date: Fri, 16 Apr 2004 08:48:22 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: recording votes
Message-Id: <c5p3ej$n1i$2@reader2.nmix.net>


"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:qkFfc.24338$2Z6.1012774@news20.bellglobal.com...
>
> "Robin" <robin @ infusedlight.net> wrote in message
> news:c5n876$cq$1@reader2.nmix.net...
> >
> > "user99" <user99@austin.rr.com> wrote in message
> > news:a16bd472.0404151512.be42d3e@posting.google.com...
> > > my page has a drop down with names which
> > > people can vote for.  any ideas on how
> > > i can record the individual count of
> > > votes for each name.  i'm thinking about
> > > using a text file to store the names with
> > > the vote count and incrementing the counts
> > > and then write them back to the same file.
> > >
> > > any better ideas????
> >
> > your way is how I did it for my poll unless your planning to use a
> database,
> > this seems like the best option to me....remember not to make your vote
> > files
> > world readable.
> >
> >
>
> Care to share what steps you took to ensure that multiple instances of
your
> script aren't trying to read and write to the file at the same time?

None yet, but actually at this moment I'm learning about file locking and
open() checking...later,
-Robin





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

Date: 19 Apr 2004 06:32:27 -0700
From: wherrera@lynxview.com (Bill)
Subject: regex compression?
Message-Id: <239ce42f.0404190532.62a5d851@posting.google.com>

Hello,

I wonder if anyone is aware of a package that will rewrite a set of
regex patterns to reduce their number. For example, given the four
regex patterns

/all\d+ of the/
/crab.*apple tree/
/all 3 of them/
/crabapple tree/

reduce to something like

/crab.*apple tree/
/all\d+ of them?/

that will match the same set of strings.

I don't need something that just does an 'or' of all the supplied regexes
into one though.


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

Date: 19 Apr 2004 18:02:55 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: regex compression?
Message-Id: <u97jwb3npc.fsf@wcl-l.bham.ac.uk>

wherrera@lynxview.com (Bill) writes:

> I wonder if anyone is aware of a package that will rewrite a set of
> regex patterns to reduce their number.

This question is oft asked here in various guises and I think the
answer is "no".  I think the problem is quite possibly "hard" (in the
CS sense of the word).

> For example, given the four
> regex patterns
> 
> /all\d+ of the/
> /crab.*apple tree/
> /all 3 of them/
> /crabapple tree/
> 
> reduce to something like
> 
> /crab.*apple tree/
> /all\d+ of them?/
> 
> that will match the same set of strings.

Actually it won't.

Even if I discount the missing space between /all/ and /\d+/ as a typo
it still won't.
 
> I don't need something that just does an 'or' of all the supplied regexes
> into one though.

Why?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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


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