[31321] in Perl-Users-Digest
Perl-Users Digest, Issue: 2566 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 23 11:09:43 2009
Date: Sun, 23 Aug 2009 08:09:07 -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 Sun, 23 Aug 2009 Volume: 11 Number: 2566
Today's topics:
Re: end-of-line conventions <RedGrittyBrick@SpamWeary.invalid>
Re: How to code an implicit $_ argument? <thepoet_nospam@arcor.de>
Re: How to code an implicit $_ argument? <rvtol+usenet@xs4all.nl>
Preventing lines from printing <dot@dot.dot>
Re: Preventing lines from printing <alexander.bartolich@gmx.at>
Re: Preventing lines from printing <dot@dot.dot>
Re: Preventing lines from printing <jurgenex@hotmail.com>
Re: Preventing lines from printing <tadmc@seesig.invalid>
Re: trapping errors using $! sln@netherlands.com
Re: windows one liner to output unix line feed <no@email.com>
Re: windows one liner to output unix line feed <thepoet_nospam@arcor.de>
Re: windows one liner to output unix line feed <kst-u@mib.org>
Re: windows one liner to output unix line feed <sbryce@scottbryce.com>
Re: windows one liner to output unix line feed sln@netherlands.com
Re: windows one liner to output unix line feed sln@netherlands.com
Re: windows one liner to output unix line feed <thepoet_nospam@arcor.de>
Re: windows one liner to output unix line feed <rvtol+usenet@xs4all.nl>
Re: windows one liner to output unix line feed <hjp-usenet2@hjp.at>
Re: windows one liner to output unix line feed <sbryce@scottbryce.com>
WWW::Mechanize - using click() <john1949@yahoo.com>
Re: WWW::Mechanize - using click() <no@email.com>
Re: WWW::Mechanize - using click() <john1949@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 23 Aug 2009 13:28:23 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.invalid>
Subject: Re: end-of-line conventions
Message-Id: <v9WdnR7V0MN3qAzXnZ2dnUVZ8nidnZ2d@bt.com>
Ben Morrow wrote:
> Quoth Jürgen Exner <jurgenex@hotmail.com>:
>> Willem <willem@stack.nl> wrote:
>>> Jürgen Exner wrote:
>>> ) But then how come that the file created by this little program
>>> )
>>> ) open FOO, ">" , "foo";
>>> ) print FOO "k\n" x 20;
>>> ) close FOO;
>>> )
>>> ) is 60 bytes long instead of 40 as would to be expected if the 'k' and
>>> ) the "\n" each were only one byte long?
>>>
>>> Because the I/O routine translates the newlines.
>> So, I guess you are saying that there is a context where "\n" does mean
>> two characters, contrary to Ben's statement:
>> "\n" can *never* mean "\015\012"
>
> No. "\n" means "\012". Your FOO filehandle has a :crlf layer on it,
> which translates "\012" to "\015\012" on output. You will get exactly
> the same result if you run
>
> open FOO, ">", "foo";
> print FOO "k\012" x 20;
> close FOO;
>
> so the CRLF newlines have nothing to do with your use of "\n".
So it seems.
C:\> perl -e "print length qq(A\n)"
2
C:\> perl -e "print unpack 'H*', qq(A\n)"
410a
C:\> perl -e "print qq(A\n)" | od -t x1
0000000 41 0d 0a
0000003
C:\> perl -e "print qq(A\n)" | od -a
0000000 A cr nl
0000003
For most purposes you can get away with thinking that "\n" represents
whatever line-ending sequence is appropriate for the current platform. I
did for a long time. Obviously there are cases where it becomes apparent
that the truth is a little more complicated. But only a little.
--
RGB
------------------------------
Date: Sun, 23 Aug 2009 12:04:24 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: How to code an implicit $_ argument?
Message-Id: <4a9113fb$0$30229$9b4e6d93@newsspool1.arcor-online.net>
Ilya Zakharevich wrote:
> On 2009-08-19, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
>>>> if (@_ == 0) {
>>>> $_[0] = \$_;
>>>> goto &trim;
>>>> }
>>> push @_, $_ unless @_;
>> That pushes a copy of $_ onto @_.
>
> Thanks, indeed. (I always wanted to implement
>
> hard_set(\@array, $slot) = $var;
>
> which would alias a slot in array/hash to a scalar...)
IMHO that shouldn't be too difficult in xs (quick'n'dirty
sub for arrays):
----------------------- xs code --------------------------
I32
hard_set(array, slot, value)
AV* array
I32 slot
SV* value
PROTOTYPE:
\@$$
CODE:
if( NULL == av_store(
array,
slot,
SvREFCNT_inc(value)) )
{
SvREFCNT_dec(value);
RETVAL = 0;
} else {
RETVAL = 1;
}
OUTPUT:
RETVAL
----------------------------------------------------------
-Chris
------------------------------
Date: Sun, 23 Aug 2009 13:23:10 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: How to code an implicit $_ argument?
Message-Id: <4a91269e$0$188$e4fe514c@news.xs4all.nl>
Ilya Zakharevich wrote:
> (I always wanted to implement
>
> hard_set(\@array, $slot) = $var;
>
> which would alias a slot in array/hash to a scalar...)
Data::Alias
--
Ruud
------------------------------
Date: Sun, 23 Aug 2009 16:41:58 +1000
From: "Diamond, Mark" <dot@dot.dot>
Subject: Preventing lines from printing
Message-Id: <h6qobl$6is$1@news-01.bur.connect.com.au>
Hello (I posted this in alt.comp.lang.perl but I think it should be here)
...
I am processing multiple text files. There is a lot of pre-processing before
the file-reading commences, then each file gets read (but I don't want to
print any blank line) and then there is a lot of post-processing of each
file. In AWK I had a BEGIN block, no print lines in the middle, and a very
long END block. In Perl, I have
pre-code
while (<>) {
lots of processing of file lines with only one wanted "print"
}
post-processing
but I get a blank line output on any line that I don't actually do an
explicit print for. I thought "perl -n" would give me what I need but it
doesn't (of course) because of the wrapped "while(<>) { }" .
Please ... what should I be doing?
Mark
------------------------------
Date: Sun, 23 Aug 2009 10:31:14 +0000 (UTC)
From: Alexander Bartolich <alexander.bartolich@gmx.at>
Subject: Re: Preventing lines from printing
Message-Id: <h6r5pi$u7e$1@news.albasani.net>
Diamond, Mark wrote:
> In Perl, I have
>
> pre-code
> while (<>) {
> lots of processing of file lines with only one wanted "print"
> }
> post-processing
>
> but I get a blank line output on any line that I don't actually do an
> explicit print for. I thought "perl -n" would give me what I need but it
> doesn't (of course) because of the wrapped "while(<>) { }" .
Unless you start perl with option -p the output can only come from
statements in your script. Since you neither posted the exact command
line nor the exact script nobody can help you.
--
Brüder, in die Tonne die Freiheit,
Brüder, ein Stoppschild davor.
Egal was die Schwarzen Verlangen
Rufen wir: Ja! Brav im Chor.
------------------------------
Date: Sun, 23 Aug 2009 22:37:47 +1000
From: "Diamond, Mark" <dot@dot.dot>
Subject: Re: Preventing lines from printing
Message-Id: <h6rd6t$kq3$1@news-01.bur.connect.com.au>
Thank you Alexander. I thought I was saving unnecessary space by NOT posting
the code. As it turns out, your comment has led me to the source of the
problem.
Instead of asking myself "how can I suppress printing that I don't want?",
your comment made me look at the problems differently, and ask "how is it
that I am accidentally printing something I didn't intend?" ... and now I
have found my mistake!
Thank you again.
Mark
"Alexander Bartolich" <alexander.bartolich@gmx.at> wrote in message
news:h6r5pi$u7e$1@news.albasani.net...
> Diamond, Mark wrote:
>> In Perl, I have
>>
>> pre-code
>> while (<>) {
>> lots of processing of file lines with only one wanted "print"
>> }
>> post-processing
>>
>> but I get a blank line output on any line that I don't actually do an
>> explicit print for. I thought "perl -n" would give me what I need but it
>> doesn't (of course) because of the wrapped "while(<>) { }" .
>
> Unless you start perl with option -p the output can only come from
> statements in your script. Since you neither posted the exact command
> line nor the exact script nobody can help you.
>
> --
> Brüder, in die Tonne die Freiheit,
> Brüder, ein Stoppschild davor.
> Egal was die Schwarzen Verlangen
> Rufen wir: Ja! Brav im Chor.
------------------------------
Date: Sun, 23 Aug 2009 06:10:16 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Preventing lines from printing
Message-Id: <1qf295lmpck8lu45hs47kqhhqgli5dn34g@4ax.com>
"Diamond, Mark" <dot@dot.dot> wrote:
[,,,]
>pre-code
>while (<>) {
> lots of processing of file lines with only one wanted "print"
>}
>post-processing
>
>but I get a blank line output on any line that I don't actually do an
>explicit print for.[...]
So you are saying Perl is executing a print() without a print() being in
your code? I find that hard to believe.
Could you please provide a minimal(!) sample program that exhibits this
problem and that we can run?
jue
------------------------------
Date: Sun, 23 Aug 2009 10:06:00 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Preventing lines from printing
Message-Id: <slrnh92m4q.6jr.tadmc@tadmc30.sbcglobal.net>
Diamond, Mark <dot@dot.dot> wrote:
> what should I be doing?
Posting a short and complete program that we can run that illustrates
your problem.
Have you seen the Posting Guidelines that are posted here frequently?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sat, 22 Aug 2009 16:06:13 -0700
From: sln@netherlands.com
Subject: Re: trapping errors using $!
Message-Id: <rgt095dtdn899ruuu8goca91k1c952ov7m@4ax.com>
On Fri, 21 Aug 2009 17:16:21 +0100, "John" <john1949@yahoo.com> wrote:
>
>
>At the moment I'm using :
>
>eval {read (STDIN,$request,$length);};
>if ($@ ne '') {$response=$error1}
>
>which appears to be working.
>
>Regards
>John
>
>
That will trap fatal errors from read.
An example is an undefined filehandle.
For some reason, file i/o does not take kindly
to undefined'ness when a handle is passed around
internally so much. Theorehtically, that may cause
a program crash if subcode does not check for null
pointers. Believe me there is alot of C code that
is buggy. So all the entry points are checked for undef
filehandles and die serves as a warning that your
program is working on borrowed time.
There are other less aggredious errors, secondary
level, or non-fatal errors that do not generate an
exception like die. These return an undef result on
i/o operations. An example is that you opened a filehandle
but did not check if it 'failed'. In reality, you sucessfully
allocated a correct filehandle but does not have a valid file
descriptor. This does not cause Perl's internal C code to
generate a fault as a null pointer would.
But how can you trap both kinds of errors, fatal/non-fatal?
In the real world, you don't want to trap fatal errors though,
you want to let them gracefully stop your program. This gives
you an oppurtunity to fix your code, which is broken.
I don't recommend trapping fatal errors, but if you want to
trap all errors (fatal/non-fatal) below is one way to do it.
-sln
---------------------------------------------------
use strict;
use warnings;
my ($buf,$length) = ('',5);
# Invoke error #1, NON - FATAL error on read.
# File doesen't exist, however, $fh is valid
open my $fh, '<', 'notexists.txt';
# Invoke error #2, FATAL error on read
#my $fh;
open STDERR, '>errors.txt';
{
local $!;
my $status = eval { read ($fh, $buf, $length) };
$@ =~ s/\s+$//;
if ($@ || (!$status && $!)) {
print "Error in read: ". ($@ ? $@ : $! ). "\n";
}
}
print "More code ...\n";
exit;
__END__
------------------------------
Date: Sat, 22 Aug 2009 16:29:32 +0100
From: Brian Wakem <no@email.com>
Subject: Re: windows one liner to output unix line feed
Message-Id: <7fah6tF2k4do7U1@mid.individual.net>
David Harmon wrote:
> On 19 Aug 2009 20:25:50 GMT in comp.lang.perl.misc, Glenn Jackman
> <glennj@ncf.ca> wrote,
>>At 2009-08-19 01:28PM, "boman" wrote:
>>> I have a simple one liner running on Windows that does a substitution.
>>> However, with the -p option, the line endings are coming out \r\n, and
>>> I need them to be just \n.
>>>
>>> perl -pi.bak -e "s|foo|bar|g" myfile.txt
>>
>>perhaps you need to chomp the windows line ending, and add the unix line
>>ending manually:
>>
>> perl -pi.bak -e "s|foo|bar|g; chomp; print qq{$_\n}" myfile.txt
>
> How could that work when the output stream converts \n to the
> system-defined line ending?
It wouldn't.
Using \x0A instead of \n should work.
--
Brian Wakem
------------------------------
Date: Sat, 22 Aug 2009 19:47:46 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: windows one liner to output unix line feed
Message-Id: <4a902f1a$0$32666$9b4e6d93@newsspool2.arcor-online.net>
Brian Wakem wrote:
> David Harmon wrote:
>> On 19 Aug 2009 20:25:50 GMT in comp.lang.perl.misc, Glenn Jackman
>> <glennj@ncf.ca> wrote,
>>> At 2009-08-19 01:28PM, "boman" wrote:
>>>> I have a simple one liner running on Windows that does a substitution.
>>>> However, with the -p option, the line endings are coming out \r\n, and
>>>> I need them to be just \n.
>>>>
>>>> perl -pi.bak -e "s|foo|bar|g" myfile.txt
>>> perhaps you need to chomp the windows line ending, and add the unix line
>>> ending manually:
>>>
>>> perl -pi.bak -e "s|foo|bar|g; chomp; print qq{$_\n}" myfile.txt
>> How could that work when the output stream converts \n to the
>> system-defined line ending?
>
> It wouldn't.
Of couse it does.
> Using \x0A instead of \n should work.
How about testing for yourself beforehand?
Something that works here (ActivePerl 5.8.8):
perl -pi.orig -e "binmode(ARGVOUT); s|foo|bar|g" myfile.txt
Win32 Perl sadly ignores settings in $ENV{PERLIO} or passed via
the open pragma for the ARGVOUT handle, at least in 5.8.8 and
5.9.x<=5 versions, but maybe this has changed in more recent releases.
-Chris
------------------------------
Date: Sat, 22 Aug 2009 14:54:06 -0700
From: Keith Thompson <kst-u@mib.org>
Subject: Re: windows one liner to output unix line feed
Message-Id: <lnfxbjpla9.fsf@nuthaus.mib.org>
Brian Wakem <no@email.com> writes:
> David Harmon wrote:
>
>> On 19 Aug 2009 20:25:50 GMT in comp.lang.perl.misc, Glenn Jackman
>> <glennj@ncf.ca> wrote,
>>>At 2009-08-19 01:28PM, "boman" wrote:
>>>> I have a simple one liner running on Windows that does a substitution.
>>>> However, with the -p option, the line endings are coming out \r\n, and
>>>> I need them to be just \n.
>>>>
>>>> perl -pi.bak -e "s|foo|bar|g" myfile.txt
>>>
>>>perhaps you need to chomp the windows line ending, and add the unix line
>>>ending manually:
>>>
>>> perl -pi.bak -e "s|foo|bar|g; chomp; print qq{$_\n}" myfile.txt
>>
>> How could that work when the output stream converts \n to the
>> system-defined line ending?
>
>
> It wouldn't.
>
> Using \x0A instead of \n should work.
That seems unlikely, since "\x0a" and "\n" have exactly the same
value.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
------------------------------
Date: Sat, 22 Aug 2009 18:08:20 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: windows one liner to output unix line feed
Message-Id: <h6q1aj$7ou$1@news.eternal-september.org>
Keith Thompson wrote:
> Brian Wakem <no@email.com> writes:
>> Using \x0A instead of \n should work.
>
> That seems unlikely, since "\x0a" and "\n" have exactly the same
> value.
Not on a Windows system.
------------------------------
Date: Sat, 22 Aug 2009 17:35:53 -0700
From: sln@netherlands.com
Subject: Re: windows one liner to output unix line feed
Message-Id: <pt2195hinjvqsk92o2m4kgpadfina0s9qp@4ax.com>
On Sat, 22 Aug 2009 14:54:06 -0700, Keith Thompson <kst-u@mib.org> wrote:
>Brian Wakem <no@email.com> writes:
>> David Harmon wrote:
>>
>>> On 19 Aug 2009 20:25:50 GMT in comp.lang.perl.misc, Glenn Jackman
>>> <glennj@ncf.ca> wrote,
>>>>At 2009-08-19 01:28PM, "boman" wrote:
>>>>> I have a simple one liner running on Windows that does a substitution.
>>>>> However, with the -p option, the line endings are coming out \r\n, and
>>>>> I need them to be just \n.
>>>>>
>>>>> perl -pi.bak -e "s|foo|bar|g" myfile.txt
>>>>
>>>>perhaps you need to chomp the windows line ending, and add the unix line
>>>>ending manually:
>>>>
>>>> perl -pi.bak -e "s|foo|bar|g; chomp; print qq{$_\n}" myfile.txt
>>>
>>> How could that work when the output stream converts \n to the
>>> system-defined line ending?
>>
>>
>> It wouldn't.
>>
>> Using \x0A instead of \n should work.
>
>That seems unlikely, since "\x0a" and "\n" have exactly the same
>value.
I don't know how unix deals with CR. Apparently it just does LF's
on output instead of CRLF.
It really doesen't matter what the :crlf layer does in unix.
It only matters how the console device interprets CR's as a tty.
You can have a thousand CR's and one LF before you print and it will
still print on the next line (Mac may be different).
If his file eol is all CR's ala Mac, then he opened it without an eol
and processed the whole file as one line. Otherwise, a series of
text embedded with just CR's on a console where a CR is a control character,
will result in overwrites of the lines without LF's.
If I had a unix machine I could try it out. It seems it would be a major
fopah if Perl didn't get the basic unix console correct, lol.
binmode (STDOUT, ":raw");
print " \nthis \x0a is \x0d\x0d\x0d\x0d\x0a a \x0a test\x0d\x0d\x0a";
print " \nthis \x0a\x0d is \x0d\x0d\x0d\x0d\x0a\x0d a \x0a test\x0d\x0d\x0a";
print " \nthis \x0d is \x0d\x0d\x0d\x0d\x0d a \x0d test\x0d\x0d\x0d";
-sln
------------------------------
Date: Sat, 22 Aug 2009 17:37:16 -0700
From: sln@netherlands.com
Subject: Re: windows one liner to output unix line feed
Message-Id: <go3195dpvsgrhq82ke5qlr6mf6ois71n1g@4ax.com>
On Sat, 22 Aug 2009 18:08:20 -0600, Scott Bryce <sbryce@scottbryce.com> wrote:
>Keith Thompson wrote:
>> Brian Wakem <no@email.com> writes:
>>> Using \x0A instead of \n should work.
>>
>> That seems unlikely, since "\x0a" and "\n" have exactly the same
>> value.
>
>
>Not on a Windows system.
Sure they do. Exactly, identically the same.
-sln
------------------------------
Date: Sun, 23 Aug 2009 08:54:40 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: windows one liner to output unix line feed
Message-Id: <4a90e78e$0$31870$9b4e6d93@newsspool3.arcor-online.net>
sln@netherlands.com wrote:
[...]
> It really doesen't matter what the :crlf layer does in unix.
> It only matters how the console device interprets CR's as a tty.
> You can have a thousand CR's and one LF before you print and it will
> still print on the next line (Mac may be different).
I think you're mixing up two different things here, one is
text file IO (and the way Perl implements it on different
platforms) and the other is console IO, which would only
apply when piping/directing to or from a perl script.
> If his file eol is all CR's ala Mac, then he opened it without an eol
> and processed the whole file as one line. Otherwise, a series of
> text embedded with just CR's on a console where a CR is a control character,
> will result in overwrites of the lines without LF's.
And here you're mixing up Perl's behaviour for input line separators
and output line separators too. Using the "-i" switch, there's no
console involved, Perl simply opens a file and sequencially inserts
what gets passed to print. If the file has been opened with a :crlf
layer, this just means that any newlines encountered in the process
are replaced by a sequence of carriage return plus newline.
What a console shows you when you cat the file contents is a very
different thing.
> If I had a unix machine I could try it out. It seems it would be a major
> fopah if Perl didn't get the basic unix console correct, lol.
Again, what's that got to do with a console? You're seriously getting
off the track.
-Chris
------------------------------
Date: Sun, 23 Aug 2009 13:32:40 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: windows one liner to output unix line feed
Message-Id: <4a9128d8$0$185$e4fe514c@news.xs4all.nl>
Scott Bryce wrote:
> Keith Thompson wrote:
>> Brian Wakem <no@email.com> writes:
>>> Using \x0A instead of \n should work.
>>
>> That seems unlikely, since "\x0a" and "\n" have exactly the same
>> value.
>
> Not on a Windows system.
You are still mixing up layers.
Find out about PerlIO,
see for starters `perldoc -f binmode`:
The operating system, device drivers, C libraries, and Perl run-time
system all work together to let the programmer treat a single character
("\n") as the line terminator, irrespective of the external
representation. On many operating systems, the native text file
representation matches the internal representation, but on some
platforms the external representation of "\n" is made up of more than
one character.
Lasagna! How Latin to name the contents after the container.
--
Ruud
------------------------------
Date: Sun, 23 Aug 2009 13:44:09 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: windows one liner to output unix line feed
Message-Id: <slrnh92asa.q41.hjp-usenet2@hrunkner.hjp.at>
On 2009-08-23 00:08, Scott Bryce <sbryce@scottbryce.com> wrote:
> Keith Thompson wrote:
>> Brian Wakem <no@email.com> writes:
>>> Using \x0A instead of \n should work.
>>
>> That seems unlikely, since "\x0a" and "\n" have exactly the same
>> value.
>
>
> Not on a Windows system.
Please.
Is it really so hard to test your assumptions before posting them?
Especially when several regulars have already explained that your
assumptions are wrong?
| Microsoft Windows [Version 6.0.6001]
| Copyright (c) 2006 Microsoft Corporation. Alle Rechte vorbehalten.
|
| C:\>perl -le "print qq{\n} eq qq{\x0A}"
| 1
|
| C:\>perl -v
|
| This is perl, v5.10.0 built for MSWin32-x64-multi-thread
| (with 5 registered patches, see perl -V for more detail)
|
| Copyright 1987-2007, Larry Wall
|
| Binary build 1004 [287188] provided by ActiveState http://www.ActiveState.com
| Built Sep 3 2008 12:22:07
hp
------------------------------
Date: Sun, 23 Aug 2009 07:58:51 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: windows one liner to output unix line feed
Message-Id: <h6ri02$1lv$1@news.eternal-september.org>
Peter J. Holzer wrote:
> On 2009-08-23 00:08, Scott Bryce <sbryce@scottbryce.com> wrote:
>> Keith Thompson wrote:
>>> Brian Wakem <no@email.com> writes:
>>>> Using \x0A instead of \n should work.
>>> That seems unlikely, since "\x0a" and "\n" have exactly the same
>>> value.
>>
>> Not on a Windows system.
>
> Please.
>
> Is it really so hard to test your assumptions before posting them?
Actually, I DID test this.
-----------
use strict;
use warnings;
open my $OUTFILE, '>', 'test.txt' or die 'Cannot open test.txt';
print $OUTFILE "A line of text\n";
print $OUTFILE "A line of text\n";
close $OUTFILE or die 'cannot close test.txt';
-----------
Both lines in test.txt end in \x0D\x0A
But now I see my mistake. If I binmode $OUTFILE, then both lines end in
\x0A.
The assumption I was making is consistent with the documentation:
The operating system, device drivers, C libraries, and Perl run-time
system all work together to let the programmer treat a single character
(\n ) as the line terminator, irrespective of the external representation.
which suggests that "\n" does not have a specific ASCII value. So the
bottom line is that on a Windows system, the value of "\n" depends on
whether you are working in text mode or binary mode.
A search of the docs for "\n" came up blank, but as someone else pointed
out, everything is spelled out in the docs under binmode.
I stand somewhat corrected.
------------------------------
Date: Sat, 22 Aug 2009 12:18:22 +0100
From: "John" <john1949@yahoo.com>
Subject: WWW::Mechanize - using click()
Message-Id: <h6ok5q$a7a$1@news.albasani.net>
Hi
I've done my @LINKS = $agent->links(); and found the link and I've called
it $button.
my $button="results.asp?page=4";
my $response=$agent->click($button);
print $response->content();
Well, it does not work, So, how do you pass the link to click()?
Regards
John
------------------------------
Date: Sat, 22 Aug 2009 16:33:34 +0100
From: Brian Wakem <no@email.com>
Subject: Re: WWW::Mechanize - using click()
Message-Id: <7fahefF2k4do7U2@mid.individual.net>
John wrote:
> Hi
>
> I've done my @LINKS = $agent->links(); and found the link and I've called
> it $button.
>
> my $button="results.asp?page=4";
> my $response=$agent->click($button);
> print $response->content();
>
> Well, it does not work, So, how do you pass the link to click()?
>
> Regards
> John
Button or link?
$agent->click() only works with form buttons. I think you want to click a
link. Use $agent->follow_link() instead.
Read the docs for the correct systax:
http://search.cpan.org/~petdance/WWW-Mechanize-1.60/lib/WWW/Mechanize.pm#$mech-%3Efollow_link(...)
--
Brian Wakem
------------------------------
Date: Sat, 22 Aug 2009 19:51:08 +0100
From: "John" <john1949@yahoo.com>
Subject: Re: WWW::Mechanize - using click()
Message-Id: <h6pemn$inn$1@news.albasani.net>
"Brian Wakem" <no@email.com> wrote in message
news:7fahefF2k4do7U2@mid.individual.net...
> John wrote:
>
>> Hi
>>
>> I've done my @LINKS = $agent->links(); and found the link and I've
>> called
>> it $button.
>>
>> my $button="results.asp?page=4";
>> my $response=$agent->click($button);
>> print $response->content();
>>
>> Well, it does not work, So, how do you pass the link to click()?
>>
>> Regards
>> John
>
>
> Button or link?
>
> $agent->click() only works with form buttons. I think you want to click a
> link. Use $agent->follow_link() instead.
>
> Read the docs for the correct systax:
> http://search.cpan.org/~petdance/WWW-Mechanize-1.60/lib/WWW/Mechanize.pm#$mech-%3Efollow_link(...)
>
>
>
> --
> Brian Wakem
Hi Brian
Many thanks. That was it. It's working fine now.
Regards
John
------------------------------
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 V11 Issue 2566
***************************************