[30859] in Perl-Users-Digest
Perl-Users Digest, Issue: 2104 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 8 09:09:45 2009
Date: Thu, 8 Jan 2009 06:09: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, 8 Jan 2009 Volume: 11 Number: 2104
Today's topics:
Re: Amateure erotik , webcam sexy dance and more !! <morgulini@gmail.com>
Re: Big Boobs on Parade <morgulini@gmail.com>
loops in perl automated ftp <banzai@ll.com>
Re: loops in perl automated ftp <clauskick@hotmail.com>
Re: mail address validation <g_m@remove-comcast.net>
Re: mail address validation <g_m@remove-comcast.net>
Re: mail address validation <g_m@remove-comcast.net>
Re: mail address validation <g_m@remove-comcast.net>
Re: opening a file <ryan.mccoskrie@gmail.com>
Re: opening a file <george@example.invalid>
Re: opening a file <RedGrittyBrick@spamweary.invalid>
Re: opening a file <smallpond@juno.com>
Re: Very Cute And Very Sexy Blonde Stripping <morgulini@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 8 Jan 2009 00:56:37 -0800 (PST)
From: Morgulini <morgulini@gmail.com>
Subject: Re: Amateure erotik , webcam sexy dance and more !!
Message-Id: <dad490ea-f327-4795-a0c5-e0554770ff32@p2g2000prn.googlegroups.com>
My handsome boyfriend is a real fucking machine! He can drill my wet
dripping slit with his immense pecker for hours nonstop. Now you are
offered the best videos selected from our young home porn collection.
Young teenage tube: http://teentube.com.cn/
This guy knows how to make me experience the strongest emotions in my
life and to tell the truth I cum time after time when he=92s working my
tight slit with his big meaty sausage. Now we are going to prove you
that! Sit back and enjoy our amateur movies: http://teentube.com.cn/
Tags: young teenage tube, fucking machine, wet dripping slit, young
home porn, tight slit, amateur movies
------------------------------
Date: Thu, 8 Jan 2009 00:57:58 -0800 (PST)
From: Morgulini <morgulini@gmail.com>
Subject: Re: Big Boobs on Parade
Message-Id: <7c343d9b-eaf5-4569-9fd2-20aa26a38c1d@e1g2000pra.googlegroups.com>
My handsome boyfriend is a real fucking machine! He can drill my wet
dripping slit with his immense pecker for hours nonstop. Now you are
offered the best videos selected from our young home porn collection.
Young teenage tube: http://teentube.com.cn/
This guy knows how to make me experience the strongest emotions in my
life and to tell the truth I cum time after time when he=92s working my
tight slit with his big meaty sausage. Now we are going to prove you
that! Sit back and enjoy our amateur movies: http://teentube.com.cn/
Tags: young teenage tube, fucking machine, wet dripping slit, young
home porn, tight slit, amateur movies
------------------------------
Date: Thu, 8 Jan 2009 10:25:54 -0000
From: "banzai" <banzai@ll.com>
Subject: loops in perl automated ftp
Message-Id: <gk4kbj$7uf$1@usenet01.boi.hp.com>
Need help with the following automated ftp script please;
if (defined ($ftp1)) {
$ftp1->login($FTP1user,$FTP1password) or LogError("FTP login to
$FTP1server failed");
if (defined $FTP1destination){
$ftp1->cwd($FTP1destination) or LogError("Could not change directory
to $FTP1destination on $FTP1server");
}
$ftp1->binary;
$ftp1->put("$FileBodyName.tar.gz") or LogError("Could not FTP copy
$FileBodyName.tar.gz to $FTP1server");
$ftp1->put("$DataTagName.gz") or LogError("Could not FTP copy
$DataTagName.gz to $FTP1server");
$ftp1->quit;
} else {
LogError("FTP open failed to $FTP1server, error code: $!");
}
#
I need to modify the above so that the ftp transfers (put's) are attempted
up to 5 times in case the remote server does not respond. No time delay
needed between retries.
TIA
------------------------------
Date: Thu, 8 Jan 2009 06:04:17 -0800 (PST)
From: Snorik <clauskick@hotmail.com>
Subject: Re: loops in perl automated ftp
Message-Id: <54eb5196-d4c7-411b-b0f3-9ebc4a54487a@z6g2000pre.googlegroups.com>
On 8 Jan., 11:25, "banzai" <ban...@ll.com> wrote:
> Need help with the following automated ftp script please;
>
> if (defined ($ftp1)) {
> $ftp1->login($FTP1user,$FTP1password) or LogError("FTP login to
> $FTP1server failed");
> if (defined $FTP1destination){
> $ftp1->cwd($FTP1destination) or LogError("Could not change directory
> to $FTP1destination on $FTP1server");
> }
> $ftp1->binary;
> $ftp1->put("$FileBodyName.tar.gz") or LogError("Could not FTP copy
> $FileBodyName.tar.gz to $FTP1server");
> $ftp1->put("$DataTagName.gz") or LogError("Could not FTP copy
> $DataTagName.gz to $FTP1server");
> $ftp1->quit;} else {
>
> LogError("FTP open failed to $FTP1server, error code: $!");}
>
> #
>
> I need to modify the above so that the ftp transfers (put's) are attempted
> up to 5 times in case the remote server does not respond. No time delay
> needed between retries.
>
> TIA
Why not simply use a counter variable in a while loop?
my $count = 0;
while ($count <= 4)
{
$ftp1->put("$FileBodyName.tar.gz") or LogError("Could not FTP
copy $FileBodyName.tar.gz to $FTP1server");
$ftp1->put("$DataTagName.gz") or LogError("Could not FTP copy
$DataTagName.gz to $FTP1server");
$count++;
}
?
------------------------------
Date: Thu, 8 Jan 2009 08:27:44 -0500
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: mail address validation
Message-Id: <G8KdnQtx_eOdYvjUnZ2dnUVZ_vKdnZ2d@giganews.com>
Peter J. Holzer > wrote ...
> ~greg > wrote ...
>>
>> In other words Mail::Address actually converts
>> "eBay, Inc" to "Inc. eBay".
>> (Just to be "helpful"!)
>
> Oops. I didn't know that. That may be a showstopper. I guess I'll have
> to review some of my code to check if this is a problem (but AFAIR I've
> only used Mail::Address to extract the email address, not the name).
>
> hp
I appreciate that comment, and I hope it wasn't sarcastic!
The reason it might be is that from my "research",
I'd say that yours is the more normal use.
But my newsgroup archive isn't just a mail-box. It's about
displaying posts, as HTML, for old members of a ng who
(generally) regard themselves as having become good
friends over the years. And for that the friendly-name
of the authors is important.
~~~
I mentioned criticism leveled at Mail::Address by the author of Email::Address.
And that the Mail::Address's pod criticizes itself even more severely --
"Although Mail::Address is a very popular subject for books,
and is used in many applications, it does a very poor job
on the more complex message fields. ..."
etc.
And then there's another module, Email::AddressParser, that criticizes Email::Address:
This class is a near drop-in replacement for the regex parsing of Email::Address,
which has serious issues for production use (exponential to infinite computation time in some cases).
It uses code from Mark Crispin's c-client library to implement the parsing.
The resulting parser is much more stable than the regex-based version of Email::Address.
---which sounds very promising.
But then it goes on to say: ...
Note, RFC2822 comments are removed by this version
(you can pass them in, and you can ask for them, but they will always be empty).
So Email::AddressParser is of no use to me.
(Why, pray tell, --if it can return the address(es),
--can't it also return the name and comment?
I mean, how much harder would that have been?)
~~~
So I don't trust the modules.
But as you say:
> Unfortunately, a line which contains an email address in RFC 822
> format is a rather complex thing to parse. RFC 1036 is much simpler,
> but it might still be a bit tricky.
I certainly don't trust my own understanding of the RFCs
to fantasize that I could write a fully compliant and fault-tolerant parser!
And I've looked at the regexes in these modules, and they are as horrifying
as anything I've ever seen in my life. I certainly wouldn't use them via
copy and paste.
But I still want to make a From-line parser, --probably
suitable only for my own use, -- using modules, as far
as I understand and trust them, and doing the rest myself.
Some of my code like that follows for potential comments.
I'd particularly appreciate if anyone can direct me to a large
variety of "From: " lines ( a test suite) to test it on.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Aside:
I worry about what's appropriate to post to alt.lang.perl.misc,
because I recall having been called to the carpet about it once.
But it says here:
http://www.foo.be/docs/tpj/issues/vol5_1/tpj0501-0009.html
The charter originally described it as a newsgroup
for "discussion of issues of all sorts relating to Perl."
And while on the one hand I take that to mean that discussion
about how to use a particular module, or about a non-perl
subject area (--eg CGI, --or email-address syntax)
should probably at be curtailed at some point, if that's all
it really is. On the other hand I take it to mean that discussion
should not be required to be limited to questions strictly about
syntax and semantics of the language itself. In general,
I think, questions about how to use perl to actually solve
problems, --- eg, the most sensible division between using
modules, vs rolling-your-own, --- and about whether your
own-rolled-code actually does what you think it does,
-- are more or less appropriate.
And with that said, I'll tentatively go on ....
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Parse($line)
# takes the content of a "From: " header line
# (essentially "name user@domain (comment)" ) and
# 1) translates quote-printable to perl's native utf8,
# 2) protects escaped (\.) and quoted ("...") parts against syntax interpretation
# 3) returns (safe_from, friendly_name)
# where safe_from == From with 'user@domain' replaced by 'user@...'
# and friendly_name == 'name', else 'comment', else 'user'.
# Protect($line)
# replaces \-escaped characters and quoted "..." stretches,
# with numbered escapes \e0\e, \e1\e, ...
# (where \e = escape (ESC) = dec 27, hex 1B
# which should not occur in any e-mail)
# so that, in particular, \-escaped characters " < @ > ( )
# won't be confused with syntacticly active ones.
# You can Protect() a line,
# then break it up into parts,
# and then Unprotect() each part separately,
# so long as the parts don't break up any of the \e\d+\e codes.
# Unprotect() reverses Protect().
# Trim1() removes spaces from the left and right
# Trim2() also removes ( ) [ ] < >
# DeQP() converts quoted-printable to utf-8.
use strict;
$|=1;
use MIME::AltWords qw(:all);
use Encode;
# note:
# Email::MIME and HTML::TreeBuilder
# will be used in the general program
# to get the "From: " header lines (and others)
# and to create plain text (later formated as HTML)
# from the text/plain and text/html MIME parts.
my @PRO;
sub Protect
{
my $s = shift; # a reference. protect line in place.
@PRO = ();
while( $$s =~ /^([^\\]*)(\\.)(.*)$/ )
{
# save and replace each \. with \e0\e, \e1\e, etc
push @PRO, $2;
$$s = "$1\e$#PRO\e$3";
}
while($$s =~ /^([^"]*)("[^"]*")(.*)$/)
{
# save and replace each "..." with \e2\e, \e3\e, etc
push @PRO, $2;
$$s = "$1\e$#PRO\e$3";
}
}
sub Unprotect
{
# restores protected escaped characters and quoted stretches.
my $s = shift; # not a reference
$s =~ s/\e(\d+)\e/$PRO[$1]/g;
return $s;
}
sub Trim1
{ # remove left and right spaces
my $s = shift; # not a reference
$s =~ s/^[\s]+//;
$s =~ s/[\s]+$//;
return $s;
}
sub Trim2
{ # remove left and right spaces and ( ) [ ] < >
my $s = shift; # not a reference
$s =~ s/^[\s\(\)\[\]<>"]+//;
$s =~ s/[\s\(\)\[\]<>"]+$//;
return $s;
}
sub DeQP
{
# decode quote-printable code into perl's internal utf8
my ($q,$p) = @_; # both are references. work on, and create, in place
foreach my $w ( decode_mimewords($$q) )
{
if(@{$w}>1)
{
my $x = Encode::decode( $w->[1], $w->[0] );
$$p .= defined $x ? $x : $w->[0] ;
}
else { $$p .= $w->[0] }
}
}
sub ParseFrom
{
my $line = shift;
my $from = '';
DeQP(\$line,\$from);
Protect(\$from);
my ($safe,$name);
if($from =~ /^(.*?)<([^<>@]*)@([^>@]*)>(.*)$/ )
{
# ..1.. <..2..@..3..> ..4..
# ..name.. <..user..@..domain..> ..comment..
$safe = Trim1(Unprotect( "$1<$2@...>$4" ));
$name = Trim2(Unprotect($1));
$name = Trim2(Unprotect($4) ) if $name eq '';
$name = Trim2(Unprotect($2) ) if $name eq '';
return ($safe,$name);
}
if($from =~ /^([^@]*)@([^\s\(]*)(.*)$/)
{
# ..1..@..2.. ..3..
# ..user..@..domain.. ..comment..
$safe = trim1(Unprotect( "$1@...$3" ));
$name = Trim2(Unprotect($3));
$name = Trim2(Unprotect($1)) if $name eq '';
return ($safe,$name);
}
# can't parse
$from = Unprotect($from);
return ($from,$from);
}
sub Test
{
foreach my $line (<DATA>)
{
chomp $line;
next if $line =~ /^\s*$/;
if($line =~ /^From:\s*(.*)$/) {$line = $1}
my ($safe,$name) = ParseFrom($line);
print "$line\n";
print "$safe\n";
print "$name\n";
print "\n";
}
}
Test();
__DATA__
=?iso-8859-1?q?Pete=20Sergeant?= <pete@clueball.com>
=?utf-8?Q?_=C2=A1Hola,_se=C3=B1or!?= <x@y.com>
------------------------------
Date: Thu, 8 Jan 2009 08:41:08 -0500
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: mail address validation
Message-Id: <YP-dnX7JRPuCn_vUnZ2dnUVZ_vadnZ2d@giganews.com>
this was good -- for me!
immediately i see ways to improve it
---which i would not have noticed if i hadn't posted it!
(--should not strip quotation marks unless they're balanced.
--should remove \ escape characters from the final strings
...)
------------------------------
Date: Thu, 8 Jan 2009 08:46:59 -0500
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: mail address validation
Message-Id: <e8udncii4JYanvvUnZ2dnUVZ_vOdnZ2d@giganews.com>
"Petr Vileta "fidokomik"" > >
>> http://community.opensourcedotnet.info/blogs/computer/archive/2006/09/16/Email-Address-Format-Myths.aspx
>
> Thanks a lot. This is exactly what I need.
> --
probably you should try to stay off his "plus-haters list of shame".
:)
~greg
------------------------------
Date: Thu, 8 Jan 2009 09:04:09 -0500
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: mail address validation
Message-Id: <_JydnU5HXbkNmvvUnZ2dnUVZ_vzinZ2d@giganews.com>
Now I do have a question.
The RCSs say that things like @
should be escaped,, or quoted, if they're not part of the
address syntax:
eg
"me\@play<user@domain>"
or
" "me@play"<user@domain>" "
(interestingly, just now, when i tried to type those in,
but without the outside "-" marks, OE simply refused
to let me do it! It erased the < > brackets immediately
after i typed them! (and im posting in Plain Text Format!)
Apparently OE tries to syntactically validate addresses
as you type them in! If Petr uses OE, he might be able
to use it this way to answer his own question, to some
extent.)
~~
On the other hand, there is the quote-printable MIME mechanism.
So my question is, --which should be un-done first before
trying to parse the line? Because it could conceivably make a big difference.
------------------------------
Date: Thu, 08 Jan 2009 21:25:17 +1300
From: Ryan McCoskrie <ryan.mccoskrie@gmail.com>
Subject: Re: opening a file
Message-Id: <gk4da4$m1a$1@news.albasani.net>
George wrote:
>
> I thought I would use perl instead of fortran to parse a text file, what
> with the new m// s/// capabilities at my fingertips.
>
> So it is that I need to open a text file and send it to STDOUT. This may
> come across as a contemptable FAQ to some. I've just looked at all the
> entries with the string 'file' beginning them in the index of the camel
> book, and it's huge and ambiguous to a guy who is not in the native perl
> environment, ie, a server, but simply needs to get a little io on windows.
>
> This is what I have so far:
>
> use strict;
> use warnings;
>
>
> my $divider= "%\n" # a percentage sign and a newline
>
>
> # perl scraper1.pl
>
> In fortran, the snippet would be:
>
> open(unit=50,file='ehp3.txt',form='formatted')
> do
> read(50,*,iostat=eof) line
> if (eof /= 0) exit
> write(*,*) trim(line)
> end do
> close(unit=50)
>
> Thanks for your comment.
This is all that you need
#The manuals don't really say it but files have their own data type.
#This line creates a variable called file or exits saying that it can't open
#the file with a possible explanation (the $! variable).
open( FILE, "ehp4.txt") || die "Could not open ehp3.txt $!";
#read out one line at a time until the file ends
while( <FILE> ){
print $_; #If you don't specify a file it goes to STDOUT (STandard OUTput)
#The $_ variable is created by the while statement
}
close(FILE); #This might not really be needed
On Unix type systems (Linux and BSD are not called Unix for legal reasons)
all programs are told about a set of files called stdin, stdout and stderr.
These act as the command line input / output (the last one is to prevent
error messages from being confused with normal output).
If you have a choice try switching over to Linux (FreeBSD later perhaps) and
do your programming their. Most of the perl concepts come from that sort
of environment.
I would describe my system (running Fedora Linux version 10) as a born as
PC and perl fits in very well.
The GNU Compiler Collection also has optional FORTRAN support.
------------------------------------------------------------------------
Quote of the login:
Given a choice between grief and nothing, I'd choose grief.
-- William Faulkner
------------------------------
Date: Thu, 8 Jan 2009 02:45:53 -0700
From: George <george@example.invalid>
Subject: Re: opening a file
Message-Id: <e6avbg75vurd$.1rhnd9kap9l5r.dlg@40tude.net>
On Wed, 07 Jan 2009 19:05:01 -0800, Jürgen Exner wrote:
> George <george@example.invalid> wrote:
>>
>>I thought I would use perl instead of fortran to parse a text file, what
>>with the new m// s/// capabilities at my fingertips.
>>
>>So it is that I need to open a text file
>
> perldoc -f open
>
>>and send it to STDOUT.
>
> perldoc -f print
Both of these turn up a lot of information, most of which is overkill for
this purpose. Furthermore, perl's features are simply confusing for me in
that there are so many, and I only need a little text file that's already
on my machine.
It brings up the notion of filehandles, which is fine, but it is something
I only know from C++ and in an MS development environment. I understand
how to open files in C.
>
>>This may
>>come across as a contemptable FAQ to some. I've just looked at all the
>>entries with the string 'file' beginning them in the index of the camel
>>book, and it's huge and ambiguous to a guy who is not in the native perl
>>environment, ie, a server,
>
> There is no relation between Perl and servers.
What language do sysadmins use?
>
>>but simply needs to get a little io on windows.
>>
>>This is what I have so far:
>>
>> use strict;
>> use warnings;
>>
>>
>>my $divider= "%\n" # a percentage sign and a newline
>>
>>
>># perl scraper1.pl
>>
>>In fortran, the snippet would be:
>
> I do not speak Fortran, therefore I cannot translate
> Maybe you could just describe what your program is meant to achieve, aka
> a spec?
>
> jue
Thanks for your response, jü.
Nominally, I want to delimit Larry Wall's sigs in a manner that will work
for my next identity. They look like:
%%
"And I don't like doing silly things (except on purpose)."
-- Larry Wall in <1992Jul3.191825.14435@netlabs.com>
%%
: And it goes against the grain of building small tools.
Innocent, Your Honor. Perl users build small tools all day long.
-- Larry Wall in <1992Aug26.184221.29627@netlabs.com>
%%
/* And you'll never guess what the dog had */
/* in its mouth... */
-- Larry Wall in stab.c from the perl source code
%%
, and I want to take the %% and replace it with $divider.
Otherwise I want to condition the set that this fortran program outputs. I
have no idea what to do with some of these characters.
module arjen2
type solar_system
type(solar_object), dimension(:), pointer :: object
end type
type solar_object
character(len=20) :: name
integer :: ascent_hour, ascent_minute, ascent_second
integer :: dec_degrees
real :: dec_mins, distance, azimuth, altitude
logical :: ER, UP
end type
end module arjen2
! default precision
integer, parameter:: max = 1023
integer:: ln, istat
character(len=max):: line
open(unit=50,file='eph4.txt')
do
Read(50,'(A)',IOSTAT=istat) line
ln = Len_Trim(line)
If (istat /= 0) Exit
call parser(line, ln)
write(*,*) trim(line)
end do
contains
subroutine parser(line, ln)
use arjen2
integer::ln
character(len=ln):: line
print *, line, ln
end subroutine
endprogram
! g95 eph7.f03 -o r.exe
C:\MinGW\source>g95 eph7.f03 -o r.exe
C:\MinGW\source>r
Sun 18h 41m 55s -23░ 5.4' 0.983 10.215 52.155 Up 48
Sun 18h 41m 55s -23░ 5.4' 0.983 10.215 52.155 Up
Mercury 20h 2m 16s -22░ 12.5' 1.102 22.537 37.668 Up
52
Mercury 20h 2m 16s -22░ 12.5' 1.102 22.537 37.668 Up
Venus 21h 55m 33s -14░ 16.3' 0.795 39.872 11.703 Up 51
Venus 21h 55m 33s -14░ 16.3' 0.795 39.872 11.703 Up
Moon 21h 17m 19s -15░ 2.4' 62.4 ER 36.796 22.871 Up 51
Moon 21h 17m 19s -15░ 2.4' 62.4 ER 36.796 22.871 Up
Mars 18h 11m 59s -24░ 6.1' 2.431 4.552 56.184 Up 48
Mars 18h 11m 59s -24░ 6.1' 2.431 4.552 56.184 Up
Jupiter 20h 3m 35s -20░ 49.4' 6.034 23.867 38.203 Up
52
Jupiter 20h 3m 35s -20░ 49.4' 6.034 23.867 38.203 Up
Saturn 11h 32m 59s +5░ 8.6' 9.018 -47.333 157.471 Set 53
Saturn 11h 32m 59s +5░ 8.6' 9.018 -47.333 157.471 Set
Uranus 23h 21m 30s -4░ 57.9' 20.421 48.328 -18.527 Up 53
Uranus 23h 21m 30s -4░ 57.9' 20.421 48.328 -18.527 Up
Neptune 21h 39m 30s -14░ 22.8' 30.748 38.963 16.599 Up
54
Neptune 21h 39m 30s -14░ 22.8' 30.748 38.963 16.599 Up
Pluto 18h 4m 34s -17░ 44.5' 32.543 7.443 62.142 Up 50
Pluto 18h 4m 34s -17░ 44.5' 32.543 7.443 62.142 Up
This is how the data fits with the declarations:
Pluto : name
18 ascent_hour
4 ascent_minute
34 ascent_second
-17 dec_degrees
44.5 dec_mins
32.543 distance
0 ER
7.443 altitude
62.142 azimuth
1 UP
Sorry about the longish post, but you asked.
--
George
America is a Nation with a mission - and that mission comes from our most
basic beliefs. We have no desire to dominate, no ambitions of empire. Our
aim is a democratic peace - a peace founded upon the dignity and rights of
every man and woman.
George W. Bush
Picture of the Day http://apod.nasa.gov/apod/
------------------------------
Date: Thu, 08 Jan 2009 10:25:31 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: opening a file
Message-Id: <4965d49e$0$27162$fa0fcedb@news.zen.co.uk>
Ryan McCoskrie wrote:
I hope you don't mind, I added a few comments to your advice.
> George wrote:
>
>> I thought I would use perl instead of fortran to parse a text file, what
>> with the new m// s/// capabilities at my fingertips.
>>
>> So it is that I need to open a text file and send it to STDOUT. This may
>> come across as a contemptable FAQ to some. I've just looked at all the
>> entries with the string 'file' beginning them in the index of the camel
>> book, and it's huge and ambiguous to a guy who is not in the native perl
>> environment, ie, a server, but simply needs to get a little io on windows.
>>
>> This is what I have so far:
>>
>> use strict;
>> use warnings;
always a good start.
>>
>>
>> my $divider= "%\n" # a percentage sign and a newline
>>
>>
>> # perl scraper1.pl
>>
>> In fortran, the snippet would be:
>>
>> open(unit=50,file='ehp3.txt',form='formatted')
>> do
>> read(50,*,iostat=eof) line
>> if (eof /= 0) exit
>> write(*,*) trim(line)
>> end do
>> close(unit=50)
You read from ehp3.txt and write to standard output?
You might find Perl's -p option useful.
perl -p -e "#do something with one line" ehp3.txt
>>
>> Thanks for your comment.
>
> This is all that you need
>
> #The manuals don't really say it but files have their own data type.
> #This line creates a variable called file or exits saying that it can't open
> #the file with a possible explanation (the $! variable).
> open( FILE, "ehp4.txt") || die "Could not open ehp3.txt $!";
There is a bug in that line. This is why I prefer to write
my $filename = 'ehp4.txt';
open my $handle, '<', $filename
or die "unable to open '$filename' because $!";
>
> #read out one line at a time until the file ends
> while( <FILE> ){
> print $_; #If you don't specify a file it goes to STDOUT (STandard OUTput)
"print;" is the same as "print $_;" and shorter and more idiomatic.
> #The $_ variable is created by the while statement
> }
>
> close(FILE); #This might not really be needed
>
>
I think the OP might be looking for something like
perl -p -e "s/%%/%\n/" ehp3.txt
which is roughly equivalent to
-------------------8<------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $filename = 'ehp3.txt';
open my $handle, '<', $filename
or die "unable to open '$filename' because $!";
while (<$handle>) {
s/%%/%\n/;
print;
}
close $handle;
-------------------8<------------------------------
Untested - caveat emptor.
--
RGB
------------------------------
Date: Thu, 8 Jan 2009 05:11:17 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: opening a file
Message-Id: <e37738da-e408-472e-a7a2-f4991f0e587a@35g2000pry.googlegroups.com>
On Jan 8, 4:45 am, George <geo...@example.invalid> wrote:
> On Wed, 07 Jan 2009 19:05:01 -0800, J=FCrgen Exner wrote:
> > George <geo...@example.invalid> wrote:
>
> >>I thought I would use perl instead of fortran to parse a text file, wha=
t
> >>with the new m// s/// capabilities at my fingertips.
>
> >>So it is that I need to open a text file
>
> > perldoc -f open
>
> >>and send it to STDOUT.
>
> > perldoc -f print
>
> Both of these turn up a lot of information, most of which is overkill for
> this purpose. Furthermore, perl's features are simply confusing for me i=
n
> that there are so many, and I only need a little text file that's already
> on my machine.
>
> It brings up the notion of filehandles, which is fine, but it is somethin=
g
> I only know from C++ and in an MS development environment. I understand
> how to open files in C.
>
>
filehandles are a feature of the OS and filesystems across all
languages.
What do you think logical unit means in FORTRAN?
Trying to get started in a language by reading detailed command
descriptions is like learning to paint a forest by asking a botanist
about
the cell structure of trees. Get a copy of "Learning Perl".
------------------------------
Date: Thu, 8 Jan 2009 00:56:52 -0800 (PST)
From: Morgulini <morgulini@gmail.com>
Subject: Re: Very Cute And Very Sexy Blonde Stripping
Message-Id: <df5f77d5-120e-411e-9a19-421e9d236c6d@i24g2000prf.googlegroups.com>
My handsome boyfriend is a real fucking machine! He can drill my wet
dripping slit with his immense pecker for hours nonstop. Now you are
offered the best videos selected from our young home porn collection.
Young teenage tube: http://teentube.com.cn/
This guy knows how to make me experience the strongest emotions in my
life and to tell the truth I cum time after time when he=92s working my
tight slit with his big meaty sausage. Now we are going to prove you
that! Sit back and enjoy our amateur movies: http://teentube.com.cn/
Tags: young teenage tube, fucking machine, wet dripping slit, young
home porn, tight slit, amateur movies
------------------------------
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 2104
***************************************