[22656] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4877 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 23 03:05:58 2003

Date: Wed, 23 Apr 2003 00: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           Wed, 23 Apr 2003     Volume: 10 Number: 4877

Today's topics:
        earthlink mailto/sendmail (zoot500)
    Re: earthlink mailto/sendmail (David Efflandt)
    Re: fake flocking on win32 (dan baker)
    Re: Matching multiple lines <ccsc3618@bigpond.net.au>
    Re: Need help with NDBM_File! (Cao Tran)
    Re: need help with the pod2html  <a@c.com>
    Re: network install, access via registry mod, win env (hfs2)
    Re: Newbie Help <bwalton@rochester.rr.com>
    Re: OT Perl Contract <dha@panix.com>
    Re: Q. Does ActivePerl for Windows require Apache to be (Jim)
    Re: Q. Does ActivePerl for Windows require Apache to be (Jim)
    Re: Q. Does ActivePerl for Windows require Apache to be <mgjv@tradingpost.com.au>
    Re: Q. Does ActivePerl for Windows require Apache to be <emschwar@pobox.com>
    Re: Q. Does ActivePerl for Windows require Apache to be <nospam@raytheon.com>
        Removal of newline characters (Stephen Adam)
    Re: Removal of newline characters (Walter Roberson)
    Re: Removal of newline characters <skuo@mtwhitney.nsc.com>
        split and substitute ? (Cao Tran)
    Re: split and substitute ? (Travis)
    Re: split and substitute ? <bernard.el-hagin@DODGE_THISlido-tech.net>
        Tough question for the guru's; Grep Once, Awk Twice (or (Agrapha)
    Re: Tough question for the guru's; Grep Once, Awk Twice <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 Apr 2003 22:00:11 -0700
From: zoot500@usa.com (zoot500)
Subject: earthlink mailto/sendmail
Message-Id: <62bc631.0304222100.2dd935a9@posting.google.com>

my earthlink domain has a mailto script,
but I'd prefer to use sendmail.  Elink publishes
the location of the sendmail program (/usr/lib/sendmail),
but after (literally) days of hacking, 
it doesn't seem to work.
They don't help with scripts.
Does anyone see anything wrong with this code?
TIA, zoot

#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard';
print "Content-type: text/html\n\n";
print "<html><body>";
open (MM, "|/usr/lib/sendmail -oi -t") || Err( 'open', 'file');
print MM <<"EOF"; 
print MM "\nFrom: whoever <webmaster\@mydomain.com>";
print MM "\nTo: mike <webmaster\@mydomain.com>";
print MM "\nSubject: testing sendmail";
print MM "\nBody of message is here."
EOF
close (MM);
print "Thanks for your comments.";
print "<br />DONE";
print "</body></html>";

sub Err{
  print "Content-type: text/html\n\n";
  print "the server can't $_[0] the $_[1] --  $! \n";
  exit;
}


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

Date: Wed, 23 Apr 2003 05:49:22 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: earthlink mailto/sendmail
Message-Id: <slrnbacab1.ct1.efflandt@typhoon.xnet.com>

On 22 Apr 2003 22:00:11 -0700, zoot500 <zoot500@usa.com> wrote:
> my earthlink domain has a mailto script,
> but I'd prefer to use sendmail.  Elink publishes
> the location of the sendmail program (/usr/lib/sendmail),
> but after (literally) days of hacking, 
> it doesn't seem to work.
> They don't help with scripts.
> Does anyone see anything wrong with this code?
> TIA, zoot

Your mail headers are invalid because you are using print statements 
within a "here doc", so your mail headers end up effectively:

print MM "
From: whoever <webmaster\@mydomain.com>";
print MM "
To: mike <webmaster\@mydomain.com>";
print MM "
Subject: testing sendmail";
print MM "
Body of message is here."

But if you remove the print MM <<"EOF"; and EOF it would not work 
either, because the first blank line ends the mail headers and you have 
the newlines at the wrong end of your strings.  So the newline beginning 
the From: would terminate your headers and there would be no effective To:

> #!/usr/local/bin/perl -wT
> use strict;
> use CGI ':standard';
> print "Content-type: text/html\n\n";
> print "<html><body>";
> open (MM, "|/usr/lib/sendmail -oi -t") || Err( 'open', 'file');
> print MM <<"EOF"; 
> print MM "\nFrom: whoever <webmaster\@mydomain.com>";
> print MM "\nTo: mike <webmaster\@mydomain.com>";
> print MM "\nSubject: testing sendmail";
> print MM "\nBody of message is here."
> EOF
> close (MM);
> print "Thanks for your comments.";
> print "<br />DONE";
> print "</body></html>";
> 
> sub Err{
>   print "Content-type: text/html\n\n";
>   print "the server can't $_[0] the $_[1] --  $! \n";
>   exit;
> }

So that block should either be (note blank line after headers):

print MM <<"EOF"; 
From: whoever <webmaster\@mydomain.com>
To: mike <webmaster\@mydomain.com>
Subject: testing sendmail

Body of message is here
EOF


Or (note double newline at end of last header):

print MM "From: whoever <webmaster\@mydomain.com>\n";
print MM "To: mike <webmaster\@mydomain.com>\n";
print MM "Subject: testing sendmail\n\n";
print MM "Body of message is here.\n"

-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: 22 Apr 2003 20:15:37 -0700
From: botfood@yahoo.com (dan baker)
Subject: Re: fake flocking on win32
Message-Id: <13685ef8.0304221915.1782a78e@posting.google.com>

Bob Walton <bwalton@rochester.rr.com> wrote in message news:<3EA4AF49.50901@rochester.rr.com>...
> dan baker wrote:
> 
> ...
> > win32 environment as on the eventual *nix server. The big problem is
> > that there is no flock on win32, ...
> 
> Where do you get the idea there is no flock on Win32 systems? ... True, it doesn't work on 95 or 98, 
---------
I have to have something that has a "reasonable" chance of working on
windows98.



> Your "fake" procedure will sooner or later fail due to non-atomic 
> operations.  Consider, for example, if several processes are competing 
> for your file lock.  One of them does the -f (did you perhaps mean -e?), 
> finds your lock file doesn't exist.  Then a second process does its -f, 
> before the first process does its open, also finding the lock file 
> doesn't exist.  Then the first process opens the lock file, establishing 
> its lock, and proceeds to muck with your tied file.  
------
*maybe*... but considering that the OPEN of a lock file could come
just before i tie() to the hash, and that this application is unlikely
to get hundreds of hits per second, I should be *ok*.

The only other pain is that I will have to check for orphaned lock
files that could possible get left if the script dies in the middle
with a lockfile in place. The only way I can think of is to take a
guess at the longest runtime, and  assume that if the creation time
given by stat() is older than that, assume its a stale file and zap
it.

On the bright side, I did run across an example that puts flock()
inside an eval() so that if I run it on win98 at least it wont crash
the script. I might code it to use flock on *nix* and my fake locking
on win32.

d


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

Date: Wed, 23 Apr 2003 05:22:55 GMT
From: "rjh" <ccsc3618@bigpond.net.au>
Subject: Re: Matching multiple lines
Message-Id: <Pqppa.7612$8K2.67658@news-server.bigpond.net.au>

Hi,
say my file has the form

2003/12/02 hh:mm --
---------------------
this is a piece
of multi line
text
---------------------
2003/12/01 hh:mm --
---------------------
this is a single line of text
---------------------
2003/12/01 hh:mm --
---------------------
this is another multiple
line of text
where i just write stuff
---------------------

Setting $/ to "----------------" works for matching multiple lines, but how
can i match the timestamp above the ---------------.
Is there a special var for that ? Does setting $/ to "------------" mean
that the timestamp will be missed altogether.
Should i try and match the timestamp and then set $/ to = "--------------"
once it is matched, then set $/ back to the normal RECORD separator before
matching the next timestamp.
ie

while (<>) {
    $timestamp = m/\d{4,}.*/;   # etc etc
    $/ = "------------";
    if(/\w.*/s) { $w = $_;}
    if($_ =~ /$line/){ print "$timestamp, $w\n";
}



Any thought, Recomendations most welcome.

Thanks.
rjh.


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnba74av.m4q.tadmc@magna.augustmail.com...
> rjh <ccsc3618@bigpond.net.au> wrote:
>
> > Im trying to search the file for the ---------- delimiter and then read
the
> > data into an array,  then search the
> > array for a match and then print out the array.
>
>
> Look up the  $/  variable in perlvar.pod.
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas




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

Date: 22 Apr 2003 16:37:03 -0700
From: caotran@sbcglobal.net (Cao Tran)
Subject: Re: Need help with NDBM_File!
Message-Id: <d2256902.0304221537.7234ac8d@posting.google.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<b7mgru$2dh5e$1@ID-184292.news.dfncis.de>...
> Cao Tran wrote:
> > I understand most of DB such as NDBM, ODBM, SDBM, have key+value
> > < 1k bytes.
> 
> NDBM has a 4k limit. Could GDBM (no size limit) possibly be an
> alternative for you?
> 
> See the comparison table at
> http://search.cpan.org/author/JHI/perl-5.8.0/lib/AnyDBM_File.pm
> 
> / Gunnar

I don't have permission to install anything to the system.


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

Date: Tue, 22 Apr 2003 22:09:29 -0700
From: "Alan C." <a@c.com>
Subject: Re: need help with the pod2html 
Message-Id: <vac7t3of4rl08a@corp.supernews.com>


"Atul Bhingarde" wrote in message
news:MbKoa.62503$NV.1526690@news.direcpc.com...
> Hi,
>
>     I am working on documenting my own perl scripts.
>
>     I have tried the pod2html in the past and I am happy with the tasks
> pod2html performed.

You didn't know how ie pod2html is a Perl script that gets the embedded pod
or plain old documentation from out of the appropriate either module file
and/or pod file and formats it html

??   Anyway, that's what does happens there.
>
>     The ecripts I have developed is bacsically 5 modules and the document
I
> want to create need to be interwoven and would like to keep the document
> location raltive to the origibal
>
>     Another thing is about the href option in the pod
>
>     Can some one guide me hoe I can do that

That is not part of the scope of the pod itself.  Instead, href happens
during the conversion only when pod2html is run.  href is only in the
outputted html.

A concept of parsing exists here.  (pod2html) does "Parse" the relevant
files (get the pod), take that same pod and format it (transform) it into
html.

But on my sys, the doc, if I type

perldoc perlpod

or you might try

man perlpod

That brings up documentation of how to on the pod currently and with
reference to also further places in the doc that are relevant.

There are books that include it as part of their scope as well.

>
> Thanks
>
> Atul
>
>




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

Date: 22 Apr 2003 16:51:50 -0700
From: hfs2@yahoo.com (hfs2)
Subject: Re: network install, access via registry mod, win env
Message-Id: <17f20df0.0304221551.6e0e5a77@posting.google.com>

Thanks.  I'll delve into config.pm and see what's up.

rook_5150@yahoo.com (Bryan Castillo) wrote in message news:<1bff1830.0304211651.1f8ec9a8@posting.google.com>...
> > Can you install perl on the network and access all it functionality
> > by simply updating local registries?
> > 
> 
> It's not the registries that make it difficult.  Perl has a
> configuration file Config.pm, which contains absolute paths to various
> things (some of which influences @INC).  You will have to make sure
> they are mapping the remote share to the same drive that is used in
> Config.pm. (perhaps you could change the entries to UNC file names  - 
> I seem to remember trying this, but finding that there were
> difficulties though).
> 
> Regarding registry entries, you might change some so that a .pl file
> is automatically run under perl when the file is double-clicked
> though.  You might also want the perl executable directory to be in
> the users PATH.
> 
> > If can, what registry entries?  
> > 
> > nt - 2000 - win98
> > perl - activeware 5.6.1
> > 
> > thanks


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

Date: Tue, 22 Apr 2003 22:23:00 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Newbie Help
Message-Id: <3EA5C0C1.6020809@rochester.rr.com>

entropy123 wrote:

> I need to make a program which:
> 
> 1) Opens a file
> 2) Writes name of the file just opened as the first line in a new file.
> 
> I'm working through a Perl book but can't figure this one out...thanks...
> 
> entropy
> 

use strict;
use warnings;
my $file='somefile.ext';
open IN,">$file" or die "Oops, couldn't open $file, $!";
print IN "$file\n";
close IN;

-- 
Bob Walton



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

Date: Wed, 23 Apr 2003 02:49:52 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: OT Perl Contract
Message-Id: <slrnbabvqg.lct.dha@panix2.panix.com>

In article <263dab8b.0304220743.1aba6a69@posting.google.com>,
Richard wrote:

> looking for an experienced Perl Software Engineer to develop in-house

You have posted a job posting or a resume in a technical group.

Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.

Had you read and understood the Usenet user manual posted frequently to
"news.announce.newusers", you might have already known this. :)  (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Another good source of information on how Usenet functions is
news.newusers.questions (information from which is also available at
http://www.geocities.com/nnqweb/).

Please do not explain your posting by saying "but I saw other job
postings here".  Just because one person jumps off a bridge, doesn't
mean everyone does.  Those postings are also in error, and I've
probably already notified them as well.

If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.

http://jobs.perl.org may be of more use to you

Yours for a better usenet,

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"A Marine that says 'gee whiz'?  What's he gonna do, storm the
Cunningham house?" - mst3k


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

Date: Tue, 22 Apr 2003 22:56:10 GMT
From: harley.davidsno@mailcity.com (Jim)
Subject: Re: Q. Does ActivePerl for Windows require Apache to be installed ?
Message-Id: <3ea5c777.380061@nntp.ix.netcom.com>

On Tue, 22 Apr 2003 11:05:24 GMT, helgi@decode.is (Helgi Briem) wrote:

>On Sun, 20 Apr 2003 17:42:48 GMT,
>harley.davidson@mailcity.com (Jim Jones) wrote:
>
>>>> Does ActivePerl for Windows require Apache to be installed ?
>>>
>>>No, it doesn't.
>>
>>Thank you very much for your help. I sure wish that the ActiveState
>>site mentioned that little fact which has had me confused all day.
>
>Why on earth should Activestate mention that??

OK, I just couldnt let your response go unreplied.

The simple fact is: to let certain people know what to do with it, or
what can be done with it.

For instance: I develop a language, but don't let all the
documentation go with the source code. How is the next person gooing
to know what to do with it ?  It would add one heck of a security
feature to not disclose how to use it, but what the hell good woud it
do ? 

That's just one example I can come up with, right off the bat, to
answer your question.

Anyway, I finally got myself going yesterday, with help of some of the
responses here.

And, I hope your question has been answered too.

Jim
>
>Should they also mention all the other programs that
>don't have to be installed to run Activeperl?
>
>That's a damn long list, you know.  Takes a lot of
>disk space, too.
>-- 
>Regards, Helgi Briem
>helgi DOT briem AT decode DOT is



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

Date: Tue, 22 Apr 2003 22:59:42 GMT
From: harley.davidsno@mailcity.com (Jim)
Subject: Re: Q. Does ActivePerl for Windows require Apache to be installed ?
Message-Id: <3ea5c8f7.764671@nntp.ix.netcom.com>

On Tue, 22 Apr 2003 21:34:09 +0100, David Dorward <dorward@yahoo.com>
wrote:

>Chris Olive wrote:
>
>> PerlScript REQUIRES running IIS...
>
>or Apache it seems:

Or Personal Web Server, as I also found out yesterday,
for running http Perl scripts. Otherwise, I was only able to run Perl
scripts in DOS.

Jim
>
>http://www.apache-asp.org/perlscript.html
>
>-- 
>David Dorward                                   http://david.us-lot.org/
>"You cannot rewrite history, not one line."
>                                      - The Doctor (Dr. Who: The Aztecs)



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

Date: Tue, 22 Apr 2003 23:21:43 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Q. Does ActivePerl for Windows require Apache to be installed ?
Message-Id: <slrnbabjk6.4f7.mgjv@verbruggen.comdyn.com.au>

On Tue, 22 Apr 2003 22:56:10 GMT,
	Jim <harley.davidsno@mailcity.com> wrote:
> On Tue, 22 Apr 2003 11:05:24 GMT, helgi@decode.is (Helgi Briem) wrote:
> 
>>On Sun, 20 Apr 2003 17:42:48 GMT,
>>harley.davidson@mailcity.com (Jim Jones) wrote:
>>
>>>>> Does ActivePerl for Windows require Apache to be installed ?
>>>>
>>>>No, it doesn't.
>>>
>>>Thank you very much for your help. I sure wish that the ActiveState
>>>site mentioned that little fact which has had me confused all day.
>>
>>Why on earth should Activestate mention that??
> 
> OK, I just couldnt let your response go unreplied.
> 
> The simple fact is: to let certain people know what to do with it, or
> what can be done with it.


It also does not require OpenOffice to be installed, or the Gimp or an
X11 server. You also don't need an IMAP server or an LDAP server.
Postgres is not required, and neither is Sybase, Oracle, MySQL or MS
SQL. Fortran, Ada, C, C++, Haskell, Befunge, Lisp, Python, Ruby, PHP
or Pascal compilers and interpreters are not necessary.  You can
freely uninstall your firewall software, because ActiveState Perl does
not require it.  You also do not need to keep a mail client or usenet
client around.  Furthermore, you can get rid of any installations of
Povray or any other rendering software.  You do not need to have FTP,
TFTP, POP, SMTP, telnet, SSH, DNS, DHCP, NNTP, NTP, rsync, NFS or SMB
services installed. It is not necessary for your hardware to go
"bleep" regularly, and you do not need to eat cereal for your
breakfast. [1]


Perl, even ActiveState Perl, will work fine without those, although
it can work with many of them.


> For instance: I develop a language, but don't let all the
> documentation go with the source code. How is the next person gooing
> to know what to do with it ?  It would add one heck of a security
> feature to not disclose how to use it, but what the hell good woud it
> do ?

You do that by documenting what you can do with the language and what
is required. Not what you can't do, and what isn't required.


Martien


[1] This list may or may not be exhaustive. It probably needs another
    326,494,385 entries. 
    We do not accept responsibility for failing to mention third party
    products or services that do not need to be installed with
    ActiveState Perl. Not even if it means that you get confused about
    what you don't need.

-- 
                        | 
Martien Verbruggen      | My friend has a baby. I'm writing down all
Trading Post Australia  | the noises the baby makes so later I can ask
                        | him what he meant - Steven Wright


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

Date: 22 Apr 2003 17:30:22 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Q. Does ActivePerl for Windows require Apache to be installed ?
Message-Id: <etoptne3yb5.fsf@wormtongue.emschwar>

harley.davidsno@mailcity.com (Jim) writes:
> Or Personal Web Server, as I also found out yesterday,
> for running http Perl scripts. Otherwise, I was only able to run Perl
> scripts in DOS.

Although you appear to be correct (PWS seems to be able to use
PerlScript for ASP), I don't think that's what you meant.  Perl
programs used for CGI are very different from PerlScript.  You may be
confused in that Perl programs are often called scripts, but in any
event, PerlScript != Perl Scripts.  That's one reason I try to be
clear, and say "Perl programs" as often as possible.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Tue, 22 Apr 2003 19:23:07 -0500
From: Chris Olive <nospam@raytheon.com>
Subject: Re: Q. Does ActivePerl for Windows require Apache to be installed ?
Message-Id: <H4lpa.334$35.1146@dfw-service2.ext.raytheon.com>

Jim wrote:
> On Tue, 22 Apr 2003 21:34:09 +0100, David Dorward <dorward@yahoo.com>
> wrote:
> 
> 
>>Chris Olive wrote:
>>
>>
>>>PerlScript REQUIRES running IIS...
>>
>>or Apache it seems:
> 
> 
> Or Personal Web Server, as I also found out yesterday,
> for running http Perl scripts. Otherwise, I was only able to run Perl
> scripts in DOS.
> 

PWS is IIS under the covers.  Different installer and a label of "PWS" 
placed over "IIS".  The typical Microsoft way of doing things on 
"differing" flavors of their OS (NTWS 4.0 versus NT Server 4.0 for 
example, both of which are exactly the same, just "tuned" differently.)

Chris
-----
Chris Olive
Systems Consultant
Raytheon Technical Services Corporation
Indianapolis, IN

email: olivec(AT)indy(DOT)raytheon(DOT)com



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

Date: 22 Apr 2003 16:21:40 -0700
From: 00056312@brookes.ac.uk (Stephen Adam)
Subject: Removal of newline characters
Message-Id: <945bf980.0304221521.39484a2c@posting.google.com>

Hi guys and girls, 

Very simple one here, I need to remove the new line characters from a
scalar before I more it into an array. I'm trying to use replace
feature ($searchresult =~ s/\n/ /;) but it don't seem to work. Sure
i'm just being silly.

The program downloads a search page from from google, places it in a
scalar, then removes all double spaces. After that it should remove
all of the new line chars. Then it places the result in the array. I'm
still quite new to Perl so if you could explain whats going wrong in
detail that would be great + if there are any better ways of doing
what already works then please let me know.


Thanks in advance. 

Steve 




Oh well, here is the code. 



#!C:\perl\perl.exe 

use warnings; 
use strict;
use vars qw($PARSE);
use LWP::Simple qw/$ua get/;
our @googlearray; # Here we hold the result of the search on google 
 



        
        
	
	&searchweb;
	
	



#pre  - true 
#post - yahoo and google array are filled and cleaned 

sub searchweb{

my $searchresult;         # This is a temp variable to hold web result



print "Please enter your search criteria \n";
        my $search = <STDIN>;

$ua  = LWP::UserAgent->new(env_proxy => 1, agent => 'a searching we
will go');
$searchresult = get "http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=$search";




  if ($searchresult){
  	  $searchresult =~ tr/[A-Z]/[a-z]/;     # Place result in lower
case
  	  
	  $searchresult =~ s/\n/ /;   # !! The bit that don't work!!
	  
	  
	  while (my $value = ($searchresult =~ m/  /)){	      # While double
spaces exist in $string
	          $searchresult =~ s/  / /;                     # Remove and
replace with single spaces
                 }
          @googlearray = (split//, $searchresult); 
          } else {
          print "ERROR - unable to download google search - please
check internet connection.";}


foreach my $i (@googlearray){
print "$i";
}




# Save result to file for error checking 
$PARSE = ">./parsefile.dat"; 
 open(PARSE) or die ("Can't open the file"); 
 print PARSE "$searchresult"; 
 close $PARSE;


 }

exit(0);


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

Date: 22 Apr 2003 23:40:59 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Removal of newline characters
Message-Id: <b84jub$rg9$1@canopus.cc.umanitoba.ca>

In article <945bf980.0304221521.39484a2c@posting.google.com>,
Stephen Adam <00056312@brookes.ac.uk> wrote:
:Very simple one here, I need to remove the new line characters from a
:scalar before I more it into an array. I'm trying to use replace
:feature ($searchresult =~ s/\n/ /;) but it don't seem to work. Sure
:i'm just being silly.

In your code, the most obvious thing you are missing is the 'g' 
modifier of the substitution operator:

  $searchresult =~ s/\n//g;


  $searchresult =~ s/  / /g;

You will not need that loop if you use /g .

Note: if you wanted to compress all runs of spaces into single spaces,
then you could use

  $searchresult =~ s/  +/ /g;
-- 
   So you found your solution
   What will be your last contribution?
   -- Supertramp (Fool's Overture)


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

Date: Tue, 22 Apr 2003 17:47:23 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Removal of newline characters
Message-Id: <Pine.GSO.4.21.0304221744510.29737-100000@mtwhitney.nsc.com>

On 22 Apr 2003, Walter Roberson wrote:

> In article <945bf980.0304221521.39484a2c@posting.google.com>,
> Stephen Adam <00056312@brookes.ac.uk> wrote:
> :Very simple one here, I need to remove the new line characters from a
> :scalar before I more it into an array. I'm trying to use replace
> :feature ($searchresult =~ s/\n/ /;) but it don't seem to work. Sure
> :i'm just being silly.
> 
> In your code, the most obvious thing you are missing is the 'g' 
> modifier of the substitution operator:
> 
>   $searchresult =~ s/\n//g;
> 
> 
>   $searchresult =~ s/  / /g;
> 
> You will not need that loop if you use /g .
> 
> Note: if you wanted to compress all runs of spaces into single spaces,
> then you could use
> 
>   $searchresult =~ s/  +/ /g;
> 




I think using the 'tr' operator is more efficient for these
particular tasks.  You can combine the above into one 'tr' statement:

my $search_results = "I    talk
 (long    pause)  like
 Captain Kirk.";

$search_results =~ tr/\n / /s;
print $search_results;

-- 
Hope this helps,
Steven



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

Date: 22 Apr 2003 16:32:11 -0700
From: caotran@sbcglobal.net (Cao Tran)
Subject: split and substitute ?
Message-Id: <d2256902.0304221532.29c8c812@posting.google.com>

Hi,

Here is my data from a hash key ($pages{$uhi}):

:0001:0002:0003:0004:0005

I want to split and put in an array

@Page = split (/:/, $pages{$uhi});

foreach (@Pages){print "\n"}

Output in @Page:
0001
0002
0003
0004
0005

which work fine, but I have another database that has this kind of
data:

0001 0002 0003 0003A0004 0005

I want to add to @Page and have output similiar to these:
0001
0002
0003
0003A
0004
0005

How do I write code to cover both case?  I don't know much of split
function, could someone help me with this.  One other note: I can't
write to the database.

thanks
cao tran


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

Date: Wed, 23 Apr 2003 01:48:59 GMT
From: lists@travish0yt.c0m (Travis)
Subject: Re: split and substitute ?
Message-Id: <lists-2204032148530001@192.168.1.4>

you probably want to look at the 'pack' and 'unpack' functions.

In article <d2256902.0304221532.29c8c812@posting.google.com>,
caotran@sbcglobal.net (Cao Tran) wrote:

> Hi,
> 
> Here is my data from a hash key ($pages{$uhi}):
> 
> :0001:0002:0003:0004:0005
> 
> I want to split and put in an array
> 
> @Page = split (/:/, $pages{$uhi});
> 
> foreach (@Pages){print "\n"}
> 
> Output in @Page:
> 0001
> 0002
> 0003
> 0004
> 0005
> 
> which work fine, but I have another database that has this kind of
> data:
> 
> 0001 0002 0003 0003A0004 0005
> 
> I want to add to @Page and have output similiar to these:
> 0001
> 0002
> 0003
> 0003A
> 0004
> 0005
> 
> How do I write code to cover both case?  I don't know much of split
> function, could someone help me with this.  One other note: I can't
> write to the database.
> 
> thanks
> cao tran


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

Date: Wed, 23 Apr 2003 04:59:23 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: split and substitute ?
Message-Id: <slrnbac7c1.1vo.bernard.el-hagin@gdndev25.lido-tech>

In article <d2256902.0304221532.29c8c812@posting.google.com>, Cao Tran
wrote:
> Hi,
> 
> Here is my data from a hash key ($pages{$uhi}):
> 
>:0001:0002:0003:0004:0005
> 
> I want to split and put in an array
> 
> @Page = split (/:/, $pages{$uhi});
> 
> foreach (@Pages){print "\n"}
> 
> Output in @Page:
> 0001
> 0002
> 0003
> 0004
> 0005
> 
> which work fine, but I have another database that has this kind of
> data:
> 
> 0001 0002 0003 0003A0004 0005
> 
> I want to add to @Page and have output similiar to these:
> 0001
> 0002
> 0003
> 0003A
> 0004
> 0005
> 
> How do I write code to cover both case?  I don't know much of split
> function, could someone help me with this.  One other note: I can't
> write to the database.


Is there supposed to be a space after the 'A' in the input? If not then
split() is not your friend. Or at least it's not your only friend. Maybe
something like this:

---------------------
$pages{$uhi} =~ s/A/A /; # remove this line if there is a space after A

my @Page = split /[: ]/, $pages{$uhi};
---------------------


It's hard to say if this will be good enough for you without knowing
more about your input, but for the examples above it'll work as
specified.


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: 22 Apr 2003 18:50:57 -0700
From: brian@box201.com (Agrapha)
Subject: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <11aabb15.0304221750.721fdebb@posting.google.com>

First let me say I know nothing about perl. I only know what I am
trying to do can be better served by the perl language then the way
I'm doing it now. I have 3 log files (proxyD."date") that include a
date in the name. Therefore they change every day. The files are proxy
server files. My shell script works but is inefficient with regards to
processor time. I hit the hard drive 5 times in my 40 line script. I
need to grep once and then awk twice or three times. Here is my shell
script can someone help me convert it to and efficient perl script?

#!/bin/tcsh
### Triage Script by bd

##########################
# set variable definitions
##########################
set TOT=0
set FAIL=0
set AVG=0
##########################
# end variables
##########################


cd /radius/logs
echo "Number of failures per end user"
grep $1 proxyD.* | grep ",0 " | awk '{print $4}' | sort +0 -1 | uniq
-c | sort | awk '$1 > 4 {print $1, $2}'
echo "Type of failure per end user"
grep $1 proxyD.* | grep ",0 " | awk '{print $8, $4}' | sort +0 -1 |
uniq -c | sort | awk '$1 > 4 {print $1, $2 ,$3}'
echo "Number of failures by type per access number"
grep $1 proxyD.* | grep ",0 " | awk '{print $8}' | sort +0 -1 | uniq
-c | sort
echo 'total number of calls for the past three days:'
set TOT=`grep $1 proxyD.* | grep -c Stop`
echo $TOT
echo 'total number of failed calls for past three days:'
set FAIL=`grep $1 proxyD.* | grep -c ",0 "`
echo $FAIL
###The next couple lines help me do 
###floating point division on the command line.
echo "the ACSR (using avg=(fail/total)*100) is equal to:"
set AVG=`echo $FAIL \/ $TOT \* 100 | bc -l | sed "s/\..*//"`
set ACSR=`expr 100 - $AVG`
echo $ACSR "%"
echo
echo 'script complete'


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

Date: Wed, 23 Apr 2003 04:28:13 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <x7adehvnvn.fsf@mail.sysarch.com>


this is a perl discussion group and not a rewrite my shell script in
perl for me group.

even if you did get someone to rewrite it, you don't know any perl so
how could you maintain it? will you regularly repost it here so we can
add features and fix things when the formats change?

the amount of perl you need is minimal so why don't you learn it?

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: 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.  

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


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