[24446] in Perl-Users-Digest
Perl-Users Digest, Issue: 6629 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 30 21:05:45 2004
Date: Sun, 30 May 2004 18:05:08 -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, 30 May 2004 Volume: 10 Number: 6629
Today's topics:
Re: Am I a programmer or a scripter? <doug.blot.hutcheson@nrm.blot.qld.blot.gov.blot.au>
Re: Array in a hash question? <krahnj@acm.org>
Re: Effective perl function to remove one element from <krahnj@acm.org>
How to Extract a Single Quote from a file Using GREP (Ben Nguyen)
Re: How to Extract a Single Quote from a file Using GRE (Walter Roberson)
Re: how to make the page not available in perl when cli (krakle)
Re: Login to MS Exchange to send e-mail <usenet@morrow.me.uk>
Re: Login to MS Exchange to send e-mail <grante@visi.com>
Re: Login to MS Exchange to send e-mail <Petri_member@newsguy.com>
Re: Login to MS Exchange to send e-mail <Petri_member@newsguy.com>
Re: Login to MS Exchange to send e-mail <grante@visi.com>
Re: Login to MS Exchange to send e-mail <usenet@rudn.com>
Re: Nested Foreach and Closure <krahnj@acm.org>
Re: Password scheme/Persistent session... (krakle)
Re: Perl to c <xuxu_18@yahoo.com>
Printing lines out of a text file <EmJayEm392NO-F-SPAM@yahoo.com>
Re: Printing lines out of a text file <usenet@morrow.me.uk>
Re: Printing lines out of a text file <krahnj@acm.org>
Re: Printing lines out of a text file <EmJayEm392NO-F-SPAM@yahoo.com>
Re: Printing lines out of a text file <uri@stemsystems.com>
Re: Printing lines out of a text file <matthew.garrish@sympatico.ca>
Re: Printing lines out of a text file <noreply@gunnar.cc>
Re: Problems with keep-alive connections <usenet@morrow.me.uk>
Re: Sendmail Options? <gary@tgpmakers.com>
Re: strange behavior <bik.mido@tiscalinet.it>
Viewing images in my CGI-BIN <ducott_99@yahoo.com>
Re: Viewing images in my CGI-BIN <ebohlman@omsdev.com>
Re: Viewing images in my CGI-BIN <1usa@llenroc.ude>
Re: Viewing images in my CGI-BIN <ebohlman@omsdev.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 31 May 2004 00:17:09 GMT
From: "Doug Hutcheson" <doug.blot.hutcheson@nrm.blot.qld.blot.gov.blot.au>
Subject: Re: Am I a programmer or a scripter?
Message-Id: <9Quuc.23$%m1.1496@news.optus.net.au>
"Steve The Geek" <slkleine@hotmail.com> wrote in message
news:863f122c.0405280849.a62ccff@posting.google.com...
> mike blamires <mike@mysurname.co.uk> wrote in message
news:<pan.2004.05.26.23.43.45.586892@mysurname.co.uk>...
> > On Tue, 25 May 2004 12:09:20 +0000, Mothra scribbled furiously:
> >
> > > . . . at what stage can you call yourself a Perl programmer?
>
> > Definitely semantic snobbery! Its all computer code at the end of the
day...
>
> The difference between a 'scripter' and a 'programmer' is determined
> by what happens when you bring up an error to them and ask for a fix:
>
> The Scripter will look at you and think for a moment -- and fix the
> code.
>
> The Programmer will look at you as if you've just said, 'Go shove a
> weasel up your ass,' and will blame the networking group.
>
> HTH
>
> HAND
>
> Steve the (perl/tk) Geek
LOL ! "8-D
Doug the Scripter.....
--
Remove the blots from my address to reply
------------------------------
Date: Sun, 30 May 2004 21:28:47 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Array in a hash question?
Message-Id: <40BA5215.49421D6E@acm.org>
Matt Garrish wrote:
>
> "Jamie Smyth" <jamiesmyth_uni@yahoo.ca> wrote in message
> news:120533fa.0405291457.573803fb@posting.google.com...
> > I have a hash defined as,
> >
> > my %data = (
> > 'wn_l' => $wn_l, 'wn_u' => $wn_u, 'wn_d' => $wn_d,
> > 'npts' => $#spc+1, 'spc' => [@spc], 'label' => $label,
> > );
> >
> > and I would like to extract the data in the @spc array. I tried,
> >
> > my @spc = %data{'spc'};
>
> The value for key spc is a reference to an array (hash values are always
> scalars). In order to access the array, you need to dereference the
> reference:
>
> my @array = @{ $data{'spc'} };
Also, the 'npts' entry isn't required as the array in scalar context
will return the number of elements:
my $npts = @{ $data{ spc } };
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 30 May 2004 21:39:43 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <40BA54A5.10FC0416@acm.org>
josh wrote:
>
> I am trying to find out the most efficient way to remove an element
> from an array, and have the array size shrink by one.
>
> pop, push, and splice won't work too well for me, I am trying to
> remove an element that could be in any position.
>
> Here is my current implementation (may not actually compile, just a
> example)
>
> <psuedo perl code>
> # this array is purposely unsorted
> @array = ['bob', 'alice', 'david', 'christy', 'edward', 'henry',
> 'frank'];
> @array = removeFromArray ( @array, "edward" );
>
> sub removeFromArray {
> @array = $_[0];
> $name = $_[1];
>
> for ( $i = 0; $i < @$array; $i++ ) {
> if ( $array[$i] eq $name ) {
> unset $array[$i];
> }
> }
> }
> </psuedo perl code>
>
> As you can see, this is not exactly the most efficient way of removing
> an element as the size of my array grows. And especially when I run
> this in a nested loop, say, when I want to compare two arrays and
> remove the differences, it will result in a close to BigO(n^2)
> efficiency.
>
> Is there a faster, more efficient way to remove an element from an
> array (and preferrably not BigO(n) )?
>
> Will it help if I am performinig this on an already sorted array? Then
> I can perhaps use some sort of binary search function to find the item
> I am looking for?
This will work if there is only one of $name in @array:
for my $i ( 0 .. $#array ) {
if ( $array[ $i ] eq $name ) {
splice @array, $i, 1;
last;
}
}
However, if you have multiple $name entries in @array then you need this
instead:
for my $i ( reverse 0 .. $#array ) {
if ( $array[ $i ] eq $name ) {
splice @array, $i, 1;
}
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: 30 May 2004 16:58:53 -0700
From: benn686@hotmail.com (Ben Nguyen)
Subject: How to Extract a Single Quote from a file Using GREP
Message-Id: <e604be8.0405301558.35215bae@posting.google.com>
I have some text files that on the 12th line of each file has a sentence
in quotes.
Id like to extract the sentence (without the quotes) from all
the files and put them into a single new file.
Seems like grep is designed for this type of thing, but not exactly sure
how to enter it :(
Ben
------------------------------
Date: 31 May 2004 00:23:26 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: How to Extract a Single Quote from a file Using GREP
Message-Id: <c9dttu$2ba$1@canopus.cc.umanitoba.ca>
In article <e604be8.0405301558.35215bae@posting.google.com>,
Ben Nguyen <benn686@hotmail.com> wrote:
:I have some text files that on the 12th line of each file has a sentence
:in quotes.
:Id like to extract the sentence (without the quotes) from all
:the files and put them into a single new file.
:Seems like grep is designed for this type of thing, but not exactly sure
:how to enter it :(
# untried
print NEWFILE grep { close ARGV if eof; $. == 12 ? s/^.*"(.*)".*/$1\n/ : 0 } (<>)
The close of ARGV is needed to reset the $. counter upon EOF of
each of the individual ARGV files. The $. == 12 tests for line 12.
The substitute changes the implicit $_ string in place.
Lines other than 12 have 0 returned from the BLOCK. grep makes
a list of the $_ values for which the expression was true.
You then print out that list. The line seperators were supplied
in the replacement pattern of the s/// operator.
If the 12th line has strange quotings, then you'll get strange
results. If the line does not have two double-quotes then the s///
operator will return 0 and that line will be excluded from the list.
--
How does Usenet function without a fixed point?
------------------------------
Date: 30 May 2004 12:49:01 -0700
From: krakle@visto.com (krakle)
Subject: Re: how to make the page not available in perl when click Back button
Message-Id: <237aaff8.0405301149.4747462f@posting.google.com>
Darick <darick_ang@yahoo.com.sg> wrote in message news:<aosib0tpd8vqp9dna3fni33pasqbrd5gat@4ax.com>...
> when i try to click back button in some website, the website will show
> the message in the following :-
>
> ---- start
> Warning: Page has Expired The page you requested was created using
> information you submitted in a form. This page is no longer available.
> As a security precaution, Internet Explorer does not automatically
> resubmit your information for you.
>
> To resubmit your information and view this Web page, click the Refresh
> button.
> ---- end
>
> may i know how to do this effect in perl ?
This isn't a Perl question. Nor is it relevant to this newsgroup. So
be prepared for 25 more people to tell you the same over and over...
and over again.
------------------------------
Date: Sun, 30 May 2004 18:08:43 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Login to MS Exchange to send e-mail
Message-Id: <c9d7vb$c4q$2@wisteria.csv.warwick.ac.uk>
[DON'T top-post]
Quoth "Y W Wong" <ywwong_hk@hotmail.com>:
> "Petri" <Petri_member@newsguy.com> ¦b¶l¥ó news:c9b1pt0rav@drn.newsguy.com ¤¤
> ¼¶¼g...
> > In article <c9adch$1sjv$1@news.hgc.com.hk>, Y W Wong says...
> > >>>> Ask your exchange admin to start the SMTP-, and IMAP- or
> > >>>> POP3-connectors on the Exchange Server. Then use the usual
> > >>>> mail-modules available from CPAN.
> >
> > >>> I just want to act as a simple script type MS Outlook to
> > >>> send text mail. Anyone know how ?
> >
> > >> Yes. You've just been told how. What part of the answer
> > >> didn't you understand?
> >
> > > I understood the SMTP and POP3 description.
> > > But it doesn't answer my question.
> > > I am asking how to login like MS Outlook, not by POP3 or SMTP.
> > > Hope that someone know what I am asking for.
> >
> > Do you know, yourself?
> > Use POP3 or IMAP to login to your exchange mailbox, just like Outlook
> does.
> > What's the problem?
> >
> > Actually, you probably don't even have to login at all, since you claim
> you only
> > want to send email, and SMTP authentication is not on by default in
> Exchange
> > Server.
> > use Net::SMTP; # Or anyone of the numerous free email modules on CPAN.
>
> How about POP3 cannot be enabled by some reason ?
> I think we have to send to a smarthost by SMTP, is it ?
> My requirement is not to using POP3 nor SMTP to send mail through MS
> Exchange.
> Hope u really understand what I am asking for.
You have already been given an answer to this: the only client that
knows how to talk the Exchange protocol is Outlook, so you have to be
using Win32 and then use Win32::OLE to make Outlook do what you want.
If you just want to send mail you can send it straight to your ISP's
smtp server (which will be a smarthost) using any of the email-sending
modules on CPAN.
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk The Levellers, 'Believers'
------------------------------
Date: 30 May 2004 19:20:24 GMT
From: Grant Edwards <grante@visi.com>
Subject: Re: Login to MS Exchange to send e-mail
Message-Id: <40ba33f8$0$17258$a1866201@newsreader.visi.com>
In article <c9d2bd$8be$1@news.hgc.com.hk>, Y W Wong wrote:
>>>>>> Ask your exchange admin to start the SMTP-, and IMAP- or
>>>>>> POP3-connectors on the Exchange Server. Then use the usual
>>>>>> mail-modules available from CPAN.
>>
>>>>> I just want to act as a simple script type MS Outlook to send
>>>>> text mail. Anyone know how ?
>>
>>>> Yes. You've just been told how. What part of the answer
>>>> didn't you understand?
>>
>>> I understood the SMTP and POP3 description. But it doesn't
>>> answer my question. I am asking how to login like MS Outlook,
>>> not by POP3 or SMTP. Hope that someone know what I am asking
>>> for.
>>
>> Do you know, yourself? Use POP3 or IMAP to login to your
>> exchange mailbox, just like Outlook does.
Actually, Outlook doesn't use POP3 or IMAP. Outlook _Express_
does, but that's a completely different app.
>>What's the problem?
>>
>> Actually, you probably don't even have to login at all, since
>> you claim you only want to send email, and SMTP authentication
>> is not on by default in Exchange Server. use Net::SMTP; # Or
>> anyone of the numerous free email modules on CPAN.
> How about POP3 cannot be enabled by some reason ?
QUIT TOP POSTING!
POP3 has NOTHING to do with sending e-mail.
> I think we have to send to a smarthost by SMTP, is it ?
That question doesn't make sense.
> My requirement is not to using POP3 nor SMTP to send mail
> through MS Exchange.
You CAN'T do that without using Outlook. Period. What part of
that don't you undestand?
> Hope u really understand what I am asking for.
Yes. We understand what you're asking for. That doesn't
change the answer:
YOU CAN NOT SEND EMAIL THE SAME WAY OUTLOOK DOES.
YOU *MUST* USE SMTP.
I'm now done telling you that.
--
Grant Edwards grante Yow! I need to discuss
at BUY-BACK PROVISIONS
visi.com with at least six studio
SLEAZEBALLS!!
------------------------------
Date: 30 May 2004 13:25:16 -0700
From: Petri <Petri_member@newsguy.com>
Subject: Re: Login to MS Exchange to send e-mail
Message-Id: <c9dfvc02o1o@drn.newsguy.com>
In article <40ba33f8$0$17258$a1866201@newsreader.visi.com>, Grant Edwards
says...
>>> Use POP3 or IMAP to login to your exchange mailbox, just
>>> like Outlook does.
> Actually, Outlook doesn't use POP3 or IMAP. Outlook
> _Express_ does, but that's a completely different app.
No, I'm actually referring to Outlook, which has an Internet E-mail connector
built in.
But yes, commonly you would connect via the MAPI/X.400 connector against your
Exchange mailbox, to get calendar-sharing and all the other stuff working too.
Nothing says you HAVE to use X.400 to send email, though, because you simply
don't. :)
Petri
------------------------------
Date: 30 May 2004 13:45:20 -0700
From: Petri <Petri_member@newsguy.com>
Subject: Re: Login to MS Exchange to send e-mail
Message-Id: <c9dh5002rmk@drn.newsguy.com>
In article <c9d2bd$8be$1@news.hgc.com.hk>, Y W Wong says...
>> Use POP3 or IMAP to login to your exchange mailbox, just like
>> Outlook does.
>> What's the problem?
>> Actually, you probably don't even have to login at all, since you
>> claim you only want to send email, and SMTP authentication is not
>> on by default in Exchange Server.
>> use Net::SMTP; # Or anyone of the numerous free email modules on CPAN.
> How about POP3 cannot be enabled by some reason ?
And what would that reason be?
If you can connect with a noisy interface such as MAPI, you very well should be
able to connect with a simple text protocol such as SMTP and POP3.
If there is a policy behind your refusal to use SMTP and POP3, then the policy
needs changing, because your project is stalled until it changes.
> I think we have to send to a smarthost by SMTP, is it ?
Why would you?
Once again; Tell your Exchange admin to start the SMTP connector on your
Exchange server.
You will immediately be able to send email through SMTP on your Exchange server,
just as if you would be using Outlook.
If you want to recieve email, than also tell him to start the POP3-connector.
You will immediately be able to login to your mailbox using POP3, and see all
the email in your mailbox, just as Outlook sees it.
> My requirement is not to using POP3 nor SMTP to send mail through
> MS Exchange.
Then good luck to you.
You can either reverse engineer MAPI, or use Outlooks COM-interface through
VBScript or Win32::OLE, or do nasty things to Outlook with the SendKeys()
function.
Seems you can even do that latter in Perl:
http://search.cpan.org/search?query=sendkeys&mode=all
> Hope u really understand what I am asking for.
You need to explain more thoroughly what it is you want to accomplish, and why
you can't use the obvious solution.
Petri
------------------------------
Date: 30 May 2004 21:11:06 GMT
From: Grant Edwards <grante@visi.com>
Subject: Re: Login to MS Exchange to send e-mail
Message-Id: <slrncbkjf9.dq8.grante@grante.rivatek.com>
On 2004-05-30, Petri <Petri_member@newsguy.com> wrote:
> In article <40ba33f8$0$17258$a1866201@newsreader.visi.com>, Grant Edwards
> says...
>>>> Use POP3 or IMAP to login to your exchange mailbox, just
>>>> like Outlook does.
>
>> Actually, Outlook doesn't use POP3 or IMAP. Outlook
>> _Express_ does, but that's a completely different app.
>
> No, I'm actually referring to Outlook, which has an Internet
> E-mail connector built in. But yes, commonly you would connect
> via the MAPI/X.400 connector against your Exchange mailbox, to
> get calendar-sharing and all the other stuff working too.
> Nothing says you HAVE to use X.400 to send email, though,
> because you simply don't. :)
You're right. I oversimplified things.
--
Grant Edwards grante Yow! Yow! I'm having a
at quadraphonic sensation
visi.com of two winos alone in a
steel mill!
------------------------------
Date: Sun, 30 May 2004 17:37:11 -0400
From: Jeff Breitner <usenet@rudn.com>
Subject: Re: Login to MS Exchange to send e-mail
Message-Id: <10bkksqit1mhk6e@corp.supernews.com>
Grant Edwards wrote:
> Actually, Outlook doesn't use POP3 or IMAP. Outlook _Express_
> does, but that's a completely different app.
If you set it up to talk MAPI to an Exchange Server, then no. But
Outlook talks POP3 and IMAP just fine and if told to use that with an
Exchange Server, it'll gleefully do it. Why you'd want to do that
though, is another question.
--
WWJD? JWRTFM
Rot13 for email address: yvfgf @ ehqa.pbz
------------------------------
Date: Sun, 30 May 2004 21:23:52 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Nested Foreach and Closure
Message-Id: <40BA50EE.91A14396@acm.org>
mt35 wrote:
>
> I'm trying to pass a lexical variable down from one subroutine to
> another. I have read perlfaq7 on closure (among others) and grasp the
> concept for the situation they gave, however I think I'm trying to do
> something else entirely. Also I'm only two weeks old in perl so if I'm
> going about this in totally the wrong way pointers on the right way to
> go are appreciated.
>
> I have an array of an ipfilter log (@fwlog) and a separate array of 10
> addresses (@hirate), each of which will have an entry in the ipfilter
> log more than 15 times. I want to make an additional array (@hirate1)
> of the full log entry foreach address, thus weeding out all entries
> that do not correspond to the 10 address array (@hirate).
>
> The original code with no closure performed on it:
>
> foreach (@hirate) {
> $y = $_;
> foreach (@fwlog) {
> push (@hirate1, $_) if ($_ =~ $y);
> }
> }
>
> Example Variables:
> $y = 192.168.1.81
> @fwlog = Jan 4 03:01:02 host0 ipmon[51]: 03:01:01.088578 xl0 @0:1 b
> 192.168.1.81,1047 -> 192.168.1.100,53 PR udp len 20 61 OUT
>
> The original problem I was having was @hirate1 would come out with a
> count of approx. 3000 when the original firewall log had a count of
> approx 1900.
>
> Here is what I tried:
>
> foreach (@hirate) {
> $y = $_;
> $q = max($y);
> &$q();
>
> sub max {
> return sub {
> foreach (@fwlog) {
> push (@hirate1, $_) if ($_ =~ $y);
> }
> }
> }
> }
>
> However, this brings back approx 3000 entires as well? Do I have some
> syntax wrong or am I way off point?
One problem that I can see is that you need boundaries defined in the
regular expression. In other words, the expression /10.98.2.4/ will
match '110.98.2.45', etc. Perhaps something like this will work
(untested):
my @hirate1;
LINE:
for my $line ( @fwlog ) {
for my $ip ( @hirate ) {
if ( $line =~ /\b$ip\b/ ) {
push @hirate, $line;
next LINE;
}
}
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: 30 May 2004 12:51:34 -0700
From: krakle@visto.com (krakle)
Subject: Re: Password scheme/Persistent session...
Message-Id: <237aaff8.0405301151.5f5f7435@posting.google.com>
Uri Guttman <uri@stemsystems.com> wrote in message news:<x7k6yyixjg.fsf@mail.sysarch.com>...
> >>>>> "k" == krakle <krakle@visto.com> writes:
>
> k> Uri Guttman <uri@stemsystems.com> wrote in message news:<x7isekks2a.fsf@mail.sysarch.com>...
>
> >> now go away already. you have stuck your nose into other threads
>
> k> I don't have to go away same as you don't have to read my posts.
> k> And, I reply in other threads simply because this IS Usenet. I
> k> thought replying was allowed? However, I am so wrong. Where are my
> k> morals.. where are they...
>
> you lost them in the same place as your brains. you have no reason to be
> helping others given how much you don't understand computers nor
> perl.
hmm.. I guess I must not know Perl or anything about computers since I
posted an "offtopic" post in this newsgroup. Good observation, guy
with the brains. :)
------------------------------
Date: Sun, 30 May 2004 14:29:07 -0400
From: "Profetas" <xuxu_18@yahoo.com>
Subject: Re: Perl to c
Message-Id: <e3ec17685f9a8924116c2bb37de86bec@localhost.talkaboutprogramming.com>
_______________________
Read this ;-)
http://www.perl.com/pub/a/2001/06/27/ctoperl.html
_______________________
That is not the reason the I want to translate.
------------------------------
Date: Sun, 30 May 2004 23:29:47 +0100
From: "EmJayEm" <EmJayEm392NO-F-SPAM@yahoo.com>
Subject: Printing lines out of a text file
Message-Id: <lmtuc.1427$bb2.1186@pathologist.blueyonder.net>
I have a text file with contents:
ENTRY= entry 1
here goes the contents for entry 1
here goes the contents for entry 1
here goes the contents for entry 1
ENTRY= entry 2
here goes the contents for entry 2
here goes the contents for entry 2
here goes the contents for entry 2
ENTRY= entry 3
here goes the contents for entry 3
here goes the contents for entry 3
here goes the contents for entry 2
In the text file, entry 1 is on line 1, entry 2 is on line 5, entry 3 is on
line 9.
I wish to display just one entry. eg. entry 2, like so:
here goes the contents for entry 2
here goes the contents for entry 2
here goes the contents for entry 2
I've done it like this:
# get the entry's line number in the text file
while (! file[$line_of_file]=~m/ENTRY=(.*)/) # for each line of the entry
until the next entry.
{
print file[$line_of_file]; # print the line of the entry
}
For printing entry 3 the condition in the while loop has to test the end of
the file, like so:
while ("$line_of_file" eq "$total_number_of_lines_in_file") # while not
end of file
{
print file[$line_of_file]; # print the line of the entry
}
I've tried to combine the two condition statements into one while loop as
below but it didn't work, yet the conditions work separately. Any ideas?
while ((! file[$line_of_file]=~m/ENTRY=(.*)/) || ("$line_of_file" eq
"$total_number_of_lines_in_file"))
------------------------------
Date: Sun, 30 May 2004 23:01:03 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Printing lines out of a text file
Message-Id: <c9dp3f$hk2$1@wisteria.csv.warwick.ac.uk>
Quoth "EmJayEm" <EmJayEm392NO-F-SPAM@yahoo.com>:
> I have a text file with contents:
>
> ENTRY= entry 1
> here goes the contents for entry 1
> here goes the contents for entry 1
> here goes the contents for entry 1
> ENTRY= entry 2
> here goes the contents for entry 2
> here goes the contents for entry 2
> here goes the contents for entry 2
> ENTRY= entry 3
> here goes the contents for entry 3
> here goes the contents for entry 3
> here goes the contents for entry 2
>
> In the text file, entry 1 is on line 1, entry 2 is on line 5, entry 3 is on
> line 9.
>
> I wish to display just one entry. eg. entry 2, like so:
> here goes the contents for entry 2
> here goes the contents for entry 2
> here goes the contents for entry 2
>
> I've done it like this:
>
> # get the entry's line number in the text file
>
> while (! file[$line_of_file]=~m/ENTRY=(.*)/) # for each line of the entry
^^ $
Please post real code. It is just a waste of everybody's time if you
post fake code. Have you read the posting guidelines?
> until the next entry.
> {
> print file[$line_of_file]; # print the line of the entry
> }
>
> For printing entry 3 the condition in the while loop has to test the end of
> the file, like so:
>
> while ("$line_of_file" eq "$total_number_of_lines_in_file") # while not
> end of file
> {
> print file[$line_of_file]; # print the line of the entry
> }
>
> I've tried to combine the two condition statements into one while loop as
> below but it didn't work, yet the conditions work separately. Any ideas?
>
> while ((! file[$line_of_file]=~m/ENTRY=(.*)/) || ("$line_of_file" eq
> "$total_number_of_lines_in_file"))
I think you want to look at the .. operator in scalar context. Try
something like this:
my $entry = 'entry 1';
for (@file) {
print if (/ENTRY= $entry/ ... /ENTRY=/) > 1;
}
See perldoc perlop.
Ben
--
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based
on the strictest morality. [Samuel Butler, paraphrased] ben@morrow.me.uk
------------------------------
Date: Sun, 30 May 2004 23:18:18 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Printing lines out of a text file
Message-Id: <40BA6BC0.B8E5669F@acm.org>
EmJayEm wrote:
>
> I have a text file with contents:
>
> ENTRY= entry 1
> here goes the contents for entry 1
> here goes the contents for entry 1
> here goes the contents for entry 1
> ENTRY= entry 2
> here goes the contents for entry 2
> here goes the contents for entry 2
> here goes the contents for entry 2
> ENTRY= entry 3
> here goes the contents for entry 3
> here goes the contents for entry 3
> here goes the contents for entry 2
>
> In the text file, entry 1 is on line 1, entry 2 is on line 5, entry 3 is on
> line 9.
>
> I wish to display just one entry. eg. entry 2, like so:
> here goes the contents for entry 2
> here goes the contents for entry 2
> here goes the contents for entry 2
my $entry = qr/\bentry 2\b/;
while ( <FILE> ) {
if ( /^ENTRY=(?=.*?$entry)/ ... /^ENTRY=/ and !/^ENTRY=/ ) {
print;
}
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 31 May 2004 00:26:43 +0100
From: "EmJayEm" <EmJayEm392NO-F-SPAM@yahoo.com>
Subject: Re: Printing lines out of a text file
Message-Id: <v5uuc.1688$K72.1606@pathologist.blueyonder.net>
> while ( <FILE> ) {
> if ( /^ENTRY=(?=.*?$entry)/ ... /^ENTRY=/ and !/^ENTRY=/ ) {
> print;
> }
> }
comments please.
EmJ.
------------------------------
Date: Sun, 30 May 2004 23:38:19 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Printing lines out of a text file
Message-Id: <x73c5ha3kk.fsf@mail.sysarch.com>
>>>>> "E" == EmJayEm <EmJayEm392NO-F-SPAM@yahoo.com> writes:
>> while ( <FILE> ) {
>> if ( /^ENTRY=(?=.*?$entry)/ ... /^ENTRY=/ and !/^ENTRY=/ ) {
>> print;
>> }
>> }
E> comments please.
it's intuitively obvious!
perldoc perlop and look for range
perldoc perlre and look for lookahead.
the best comments are in the docs.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 30 May 2004 19:36:00 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Printing lines out of a text file
Message-Id: <pduuc.79548$tb4.2934789@news20.bellglobal.com>
"EmJayEm" <EmJayEm392NO-F-SPAM@yahoo.com> wrote in message
news:v5uuc.1688$K72.1606@pathologist.blueyonder.net...
> > while ( <FILE> ) {
> > if ( /^ENTRY=(?=.*?$entry)/ ... /^ENTRY=/ and !/^ENTRY=/ ) {
> > print;
> > }
> > }
>
> comments please.
>
I like it!
If you mean explanation, that's usually left to the reader. Take a look at
perlre if you don't understand regular expressions and perlop if the '...'
has you confused.
Matt
------------------------------
Date: Mon, 31 May 2004 02:44:44 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Printing lines out of a text file
Message-Id: <2hvdpkFhhmjcU1@uni-berlin.de>
EmJayEm wrote:
> I have a text file with contents:
>
> ENTRY= entry 1
> here goes the contents for entry 1
> here goes the contents for entry 1
> here goes the contents for entry 1
> ENTRY= entry 2
> here goes the contents for entry 2
> here goes the contents for entry 2
> here goes the contents for entry 2
> ENTRY= entry 3
> here goes the contents for entry 3
> here goes the contents for entry 3
> here goes the contents for entry 2
>
> In the text file, entry 1 is on line 1, entry 2 is on line 5,
> entry 3 is on line 9.
>
> I wish to display just one entry. eg. entry 2, like so:
> here goes the contents for entry 2
> here goes the contents for entry 2
> here goes the contents for entry 2
A variant, playing with the input record separator (see "perldoc
perlvar"):
my $entry = qr/^\s*entry 2\b/;
{
local $/ = 'ENTRY=';
while ( <FILE> ) {
if (/$entry/) {
print /.+\n([\S\s]+?)(?:ENTRY|$)/;
last;
}
}
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 30 May 2004 18:05:40 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Problems with keep-alive connections
Message-Id: <c9d7pk$c4q$1@wisteria.csv.warwick.ac.uk>
Quoth Vincent van Scherpenseel <reply@newsgroup.invalid>:
> Hello group,
>
> I'm writing a simple script which should connect to a HTTP proxy server,
> then send a GET request and display the output of the GET request. After
> that it should continue with other tasks.
>
> It's all going well, until I use HTTP/1.1. Most HTTP/1.1 requests are
> Keep-Alive connections and thus perl keeps the connection (IO::Socket)
> alive.
>
> Here's a (much) simplified version of my code:
> > while (<$remote>) {
> > print $client $_;
> > }
> > close $remote;
>
> Now my problem is that because of the Keep-Alive connection, my script
> 'hangs' within the while-loop, and thus doesn't continue its operations. Is
> there a way to support Keep-Alive connections but still let my script
> continue like it should?
You should be using LWP to make the requests; this will deal with
Keep-alive for you (and probably disable it).
Ben
--
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based
on the strictest morality. [Samuel Butler, paraphrased] ben@morrow.me.uk
------------------------------
Date: Sun, 30 May 2004 21:17:25 +0000 (UTC)
From: Gary Mayor <gary@tgpmakers.com>
Subject: Re: Sendmail Options?
Message-Id: <c9dj12$qoo$1@hercules.btinternet.com>
Thanks Juha finnaly some useful feedback
Juha Laiho wrote:
> Gary Mayor <gary@tgpmakers.com> said:
>
>>Walter Roberson wrote:
>>
>>>In article <c9c953$99v$1@sparta.btinternet.com>,
>>>Gary Mayor <gary@tgpmakers.com> wrote:
>>>:I'm having a problem with sendmail not always sending emails.
>
> ...
>
>>>:Here's the line I use to send emails,
>>>
>>>:my $sendmail = "/usr/sbin/sendmail -oi -t";
>
> ...
> Well, the line you quoted does not send mail; it declares a variable
> called '$sendmail' and initialises it to the given value. Apparently
> later in the code you give that variable to "system" or some other
> all that will actually execute sendmail.
>
>
>>The emails just disappear looked in the logs and there's nothing giving
>>a clue, just says sent.
>
>
> Says "sent" where? In the logs? If the log says "sent", then look for
> detail saying "relay=some.host.name". So, for example here's a log entry
> of a message I sent to myself:
> sendmail[4467]: i4UHhbF9004465: to=<juha.laiho@iki.fi>, delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30318, relay=mta.inet.fi. [192.89.123.210], dsn=2.0.0, stat=Sent (Message received: 20040530174337.BGKH8747.fep14.inet.fi@ichaos.ichaos-int)
>
> So, says that it has been delivered using mailer 'relay', and has been
> accepted for delivery by mta.inet.fi. In addition, mta.inet.fi admins
> could find out more info about this message with the id listed at the
> end of the line (2004...).
>
> If there is a line like this in your maillog, then the message is delivered
> out of your machine, but may of course have been filtered by some other
> machine on the way - antispam and virus scanning software are rather
> commonplace nowadays.
------------------------------
Date: Sun, 30 May 2004 20:35:13 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: strange behavior
Message-Id: <dcmjb0djceld36fhqk44t48e4561bgfac3@4ax.com>
On Sat, 29 May 2004 20:38:12 +0200, Matija Papec <perl@my-header.org>
wrote:
>I thought that output should be the same for all four lines but they differ.
>Am I running buggy perl? (5.8.0)
> my $tmp = join ' ', map { $_ += 5*$row } 0 .. 4;
^^
^^
> print "$row - $tmp\n";
> }
>
>---------- Capture Output ----------
>2 - 10 11 12 13 14
>2 - 20 21 22 23 24
>2 - 30 31 32 33 34
>2 - 40 41 42 43 44
Althoug that += is strange and unneeded, I can't understand why you
get that output and I'd say it's not correct. However I get it too!
(perl 5.8.3 here)
But then do you have a good reason for not using
map { $_ + 5*$row } 0..4;
instead?
Also, as a side note (you probably know that)
my @tmp = map { $_ + 5*$row } 0 .. 4;
print "$row - @tmp\n";
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: Sun, 30 May 2004 21:07:56 GMT
From: "Robert TV" <ducott_99@yahoo.com>
Subject: Viewing images in my CGI-BIN
Message-Id: <M2suc.592322$Pk3.108148@pd7tw1no>
Hello, I am writing a perl script that uploads images from my computer to my
web site. The images get dumped inside a special forder in my cgi-bin. For
some reason, once the images have arrived, they cannot be viewed in my
browser. The URL is have entered are correct, but they always show up
broken. If I use my ftp program to move the images out of the cgi-bin and
into a normal html forlder they appear fine. I have also played with the
file permissions of the images when in the cgi-bin, but to no avail. Can
anyone help me? TAI
Robert
------------------------------
Date: 30 May 2004 21:25:37 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Viewing images in my CGI-BIN
Message-Id: <Xns94F9A7C8EC3B4ebohlmanomsdevcom@130.133.1.4>
"Robert TV" <ducott_99@yahoo.com> wrote in
news:M2suc.592322$Pk3.108148@pd7tw1no:
> Hello, I am writing a perl script that uploads images from my computer
> to my web site. The images get dumped inside a special forder in my
> cgi-bin. For some reason, once the images have arrived, they cannot be
> viewed in my browser. The URL is have entered are correct, but they
> always show up broken. If I use my ftp program to move the images out
> of the cgi-bin and into a normal html forlder they appear fine. I have
> also played with the file permissions of the images when in the
> cgi-bin, but to no avail. Can anyone help me? TAI
It's a web-server configuration issue, nothing Perl-specific. Web servers
are normally configured to map URLs that point into a CGI directory or
subdirectory into requests to execute code rather than to deliver files.
And there are good reasons for this to be so. If you want uploaded files
to be immediately servable, your upload handler needs to put them somewhere
they can be served from. It's that simple.
------------------------------
Date: 30 May 2004 21:25:52 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Viewing images in my CGI-BIN
Message-Id: <Xns94F9B152084A9asu1cornelledu@132.236.56.8>
"Robert TV" <ducott_99@yahoo.com> wrote in
news:M2suc.592322$Pk3.108148@pd7tw1no:
> Hello, I am writing a perl script that uploads images from my computer
> to my web site. The images get dumped inside a special forder in my
> cgi-bin. For some reason, once the images have arrived, they cannot be
> viewed in my browser. The URL is have entered are correct, but they
> always show up broken. If I use my ftp program to move the images out
> of the cgi-bin and into a normal html forlder they appear fine. I have
> also played with the file permissions of the images when in the
> cgi-bin, but to no avail. Can anyone help me? TAI
This has absolutely nothing to do with Perl.
Most probably, your web server is configured to treat everything in cgi-bin
as a program to be run. It is generally a good idea to keep content and
executable locations separate.
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
Date: 30 May 2004 21:27:15 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Viewing images in my CGI-BIN
Message-Id: <Xns94F9A81019CC9ebohlmanomsdevcom@130.133.1.4>
Eric Bohlman <ebohlman@omsdev.com> wrote in
news:Xns94F9A7C8EC3B4ebohlmanomsdevcom@130.133.1.4:
> It's a web-server configuration issue, nothing Perl-specific. Web
> servers are normally configured to map URLs that point into a CGI
> directory or subdirectory into requests to execute code rather than to
> deliver files. And there are good reasons for this to be so. If you
> want uploaded files to be immediately servable, your upload handler
> needs to put them somewhere they can be served from. It's that
> simple.
P.S. Any further discussion of this should take place in
comp.infosystems.www.authoring.cgi, since it's not Perl-specific.
------------------------------
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 6629
***************************************