RE: How long can $_ be?

2002-03-13 Thread Anette Seiler

Dear All,

the script I'm using is really very simple:

script
#!/usr/local/bin/perl -w
use strict;

while () {
  chomp;
  print \n\n$_\n\n;
}

/script

From the command line I start the script with perl script.pl. Now I 
have to enter some text. I just enter any text, either by typing or by 
cutting and pasting. I do not enter any strange characters or 
newlines. I just type in some text. I even take care to just use 
normal characters - no numbers, umlaute or anything else strange. 
As you can see, I did not play with $/.

As I wrote in my initial mail, the answer I get is not the answer I 
expect. Whenever my input is more than 256 character, instead of 
printing everything I entered, it prints only the last part of what I 
entered, everything after character 256. The first part is chopped off.

I experimented with that and had the following results:

The first line I gave was 490 characters long, $_ contained the last 
233
characters. The string was chopped off at character 257.

The second line I gave was 462 characters long, $_ contained the 
last 205 characters. The string was chopped off at character 257.

The third line I gave was 253 characters long, $_ contained the 
whole 253 characters. Nothing was chopped off.

The fourth line I gave was 839 characters long, $_ contained the 
last 68 characters. The string was chopped off at character 771.

Nikola asked: Exactly how long/big are we talking of making $_?
The fourth line is already a very long line. I don't thing it will be 
more than a 1000 characters per line.

The script above is the essence of the problem. I found the problem 
when I wrote a script that reads in a line at a time from a file. The 
script was supposed to find a url in each line with an regex, isolate 
the url and do something with it. The script did not find the url in 
lines that were longer than 256 characters, because it appeared 
more in the beginning. I then found out that it was not my regex 
that was wrong, but $_ did not give me what I wanted.

Funny enough, I am able to find the url using index and substring. 
In this way I was able to do what I wanted to do, but it does not 
help solving the problem I have. The subroutine  that worked was:

  open DATEI, $_ or die Kann die Datei $_ nicht öffnen ($!)\n;
 
  foreach my $line (DATEI) {
chomp $line;

if ($line =~ /\LI\/i) {
my $begin_url = index $line, http;
my $end_url = index $line, \ ;
my $length = ($end_url - $begin_url) ;
my $url = substr ($line, $begin_url, $length);

and so on.

I would be really grateful for an answer to the puzzle.

Kind regards

Anette



 Perl 5.004_04 on my Solaris 5.6 machine had no problems making $_ of
 length 178956970. Of course I have an elephant crap load of memory on
 this sucker.
 
 Exactly how long/big are we talking of making $_?
 
 
 -Original Message-
 From: David Gray [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, March 12, 2002 9:06 AM
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: RE: How long can $_ be?
 
 
  Is there some limit in how long the contents of the variable $_ can
  be? 
 
 Not that I'm aware of, no.
 
  I encounter this problem on Solaris machines running Perl 5.005. On
  Windows with Perl 5.6.1. no such problem was encountered.
  
  What could cause the problem?
 
 I suppose it might be a a configuration problem of some sort, but I
 doubt that. Could you show us the exact code you're using to load the
 lines from your file into $_ ?
 
  -dave
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 --
 --  The views and opinions expressed in this
 email message are the sender's own, and do not necessarily represent
 the views and opinions of Summit Systems Inc.
 


Mit freundlichen Grüßen

Anette Seiler

HBZ-NRW
Geschäftsbereich Digitale Bibliothek 
Tel.: +49-221-40075-196
Fax: +49-221-40075-190
www.hbz-nrw.de

email: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How long can $_ be?

2002-03-13 Thread Elaine -HFB- Ashton

Anette Seiler [[EMAIL PROTECTED]] quoth:
*
*From the command line I start the script with perl script.pl. Now I 
*have to enter some text. I just enter any text, either by typing or by 
*cutting and pasting. I do not enter any strange characters or 
*newlines. I just type in some text. I even take care to just use 
*normal characters - no numbers, umlaute or anything else strange. 
*As you can see, I did not play with $/.
*
*As I wrote in my initial mail, the answer I get is not the answer I 
*expect. Whenever my input is more than 256 character, instead of 
*printing everything I entered, it prints only the last part of what I 
*entered, everything after character 256. The first part is chopped off.

I believe you :) It's a 'feature' of Sun's terminal driver which only
allows lines of 256 characters.

A workaround would be to force a linewrap at 74 chars or read $_ from a
file.

e.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: How long can $_ be?

2002-03-13 Thread Peter_Farrar


I've seen this effect when using data I copied off the internet (using
Explorer) into a text file in a Unix environment.  In my case the problem
was definitely a control character within the string causing a line return
without a line feed.  It didn't show up when I viewed the file with less or
cat, or notepad on Windows, just when I manipulated it with perl, and
printed the results to the screen.  It really drove me crazy for a while.
I don't remember exactly what crudgy solution I came up with, but it sounds
like the same kind of problem.



   

Anette

Seiler  To: [EMAIL PROTECTED]

SEILER@hbz-nr   cc:   

w.deSubject: RE: How long can $_ be?  

   

03/13/2002 

06:51 AM   

   

   





Dear All,

the script I'm using is really very simple:

script
#!/usr/local/bin/perl -w
use strict;

while () {
  chomp;
  print \n\n$_\n\n;
}

/script

From the command line I start the script with perl script.pl. Now I
have to enter some text. I just enter any text, either by typing or by
cutting and pasting. I do not enter any strange characters or
newlines. I just type in some text. I even take care to just use
normal characters - no numbers, umlaute or anything else strange.
As you can see, I did not play with $/.

As I wrote in my initial mail, the answer I get is not the answer I
expect. Whenever my input is more than 256 character, instead of
printing everything I entered, it prints only the last part of what I
entered, everything after character 256. The first part is chopped off.

I experimented with that and had the following results:

The first line I gave was 490 characters long, $_ contained the last
233
characters. The string was chopped off at character 257.

The second line I gave was 462 characters long, $_ contained the
last 205 characters. The string was chopped off at character 257.

The third line I gave was 253 characters long, $_ contained the
whole 253 characters. Nothing was chopped off.

The fourth line I gave was 839 characters long, $_ contained the
last 68 characters. The string was chopped off at character 771.

Nikola asked: Exactly how long/big are we talking of making $_?
The fourth line is already a very long line. I don't thing it will be
more than a 1000 characters per line.

The script above is the essence of the problem. I found the problem
when I wrote a script that reads in a line at a time from a file. The
script was supposed to find a url in each line with an regex, isolate
the url and do something with it. The script did not find the url in
lines that were longer than 256 characters, because it appeared
more in the beginning. I then found out that it was not my regex
that was wrong, but $_ did not give me what I wanted.

Funny enough, I am able to find the url using index and substring.
In this way I was able to do what I wanted to do, but it does not
help solving the problem I have. The subroutine  that worked was:

  open DATEI, $_ or die Kann die Datei $_ nicht öffnen ($!)\n;

  foreach my $line (DATEI) {
chomp $line;

if ($line =~ /\LI\/i) {
   my $begin_url = index $line, http;
   my $end_url = index $line, \ ;
   my $length = ($end_url - $begin_url) ;
   my $url = substr ($line, $begin_url, $length);

and so on.

I would be really grateful for an answer to the puzzle.

Kind regards

Anette



 Perl 5.004_04 on my Solaris 5.6 machine had no problems making $_ of
 length 178956970. Of course I have an elephant crap load of memory on
 this sucker.

 Exactly how long/big are we talking of making $_?


 -Original Message-
 From: David Gray [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, March 12, 2002 9:06 AM
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: RE: How long can $_ be?


  Is there some limit in how long the contents of the variable $_ can
  be?

 Not that I'm aware of, no.

  I encounter this problem on Solaris machines running Perl 5.005. On
  Windows with Perl 5.6.1. no such problem was encountered.
 
  What could

RE: How long can $_ be?

2002-03-12 Thread David Gray

 Is there some limit in how long the contents of the variable $_ can 
 be? 

Not that I'm aware of, no.

 I encounter this problem on Solaris machines running Perl 5.005. 
 On Windows with Perl 5.6.1. no such problem was encountered.
 
 What could cause the problem?

I suppose it might be a a configuration problem of some sort, but I
doubt that. Could you show us the exact code you're using to load the
lines from your file into $_ ?

 -dave



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: How long can $_ be?

2002-03-12 Thread Nikola Janceski

Perl 5.004_04 on my Solaris 5.6 machine had no problems making $_ of length
178956970.
Of course I have an elephant crap load of memory on this sucker.

Exactly how long/big are we talking of making $_?


-Original Message-
From: David Gray [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 9:06 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: How long can $_ be?


 Is there some limit in how long the contents of the variable $_ can 
 be? 

Not that I'm aware of, no.

 I encounter this problem on Solaris machines running Perl 5.005. 
 On Windows with Perl 5.6.1. no such problem was encountered.
 
 What could cause the problem?

I suppose it might be a a configuration problem of some sort, but I
doubt that. Could you show us the exact code you're using to load the
lines from your file into $_ ?

 -dave



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: How long can $_ be?

2002-03-12 Thread Hanson, Robert

There is no limit on the length of a scalar in Perl other than the amount of
memory you have.  It is possible that it is splitting the newline because
you are using a multi-byte character set, or the global variable $/ (input
record seperator) was changed in the script, or you are working with binary
data.  In other words I am guessing that you have the character value 10 (a
linefeed) somewhere inside of the string, and it is splitting the string on
that.

Rob

-Original Message-
From: Anette Seiler [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 4:55 AM
To: [EMAIL PROTECTED]
Subject: How long can $_ be?


Hi!

Is there some limit in how long the contents of the variable $_ can 
be? 

The problem I have is following: my script reads a file line by line. 
These lines are fairly long. As soon as I work with the long lines 
problems arise. The script chops off the first part of the line. When I 
print $_ I don't get the whole line, but only the last part .

I made several experiments. 

The first line I gave was 490 characters long, $_ contained the last 
233 characters. The string was chopped off at character 257.

The second line I gave was 462 characters long, $_ contained the 
last 205 characters. The string was chopped off at character 257.

The third line I gave was 253 characters long, $_ contained the 
whole 253 characters. Nothing was chopped off.

The fourth line I gave was 839 characters long, $_ contained the 
last 68 characters. The string was chopped off at character 771.

I encounter this problem on Solaris machines running Perl 5.005. 
On Windows with Perl 5.6.1. no such problem was encountered.

What could cause the problem?

Kind regards

Anette
Mit freundlichen Grüßen

Anette Seiler

HBZ-NRW
Geschäftsbereich Digitale Bibliothek 
Tel.: +49-221-40075-196
Fax: +49-221-40075-190
www.hbz-nrw.de

email: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]