Re: """Wallbanger@t-online.de""" aus Eurer Verteiung nehmen!!!!!

2004-10-29 Thread Gunnar Hjalmarsson
FYI I just sent this message:
 Original Message 
Subject: Re: Bitte schreibe mir in Deutsch !!
Date: Fri, 29 Oct 2004 09:09:42 +0200
From: Gunnar Hjalmarsson
To: Spikema (Sonja Klenner)
Dear Sonja,
Thanks for your note. I did understand most of what you wrote (studied
some German once in school), but please excuse me for still replying in
English.
I'm truly sorry to hear about the death of your husband.
I made an attempt to help you by unsubscribing the address
[EMAIL PROTECTED] from the [EMAIL PROTECTED] mailing list (see
below). That should have resulted in a confirmation message, and if you
just reply to that, you should stop receiving messages from the list.
Hope that will help.
Kind regards,
Gunnar
 Original Message 
Subject: Unsubscribe request
Date: Fri, 29 Oct 2004 08:53:31 +0200
From: Gunnar Hjalmarsson <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Preventing shell redirection from creating empty file

2004-10-29 Thread Jim
 
> 
> On Tue, 26 Oct 2004, Dan Fish wrote:
> 
> > system("myscript.pl arg1 arg2 > myfile.txt");
> > 
> > What is the easiest way to prevent "myfile.txt" from being 
> created if 
> > the script dies or produces no output? (It seems the shell 
> will always 
> > create myfile.txt, regardless)
> 
> Would it be enough to just delete the file if it's empty?
> 
>   du myfile.txt | grep '^0' && rm myfile.txt
> 
> That seems easier than any other approach i can think of.
>  

How about something like this, in your perl program:
-z $file && unlink $file;



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.772 / Virus Database: 519 - Release Date: 10/1/2004
 


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




Antwort: Re: """Wallbanger@t-online.de""" aus Eurer Verteiung nehmen!!!!!

2004-10-29 Thread Manfred . Beilfuss
Hello Everybody,


Hallo Sonja,

auch von mir mein herzlichstes Beileid zum Tode Deines Mannes.

Ich uebersetze Dir kurz was Gunnar schon geschrieben hat.

Er spricht Dir auch sein Beileid aus und war so freundlich Deinen Wunsch zu
erfüllen, Deinen leider verstorbenen
Mann aus der Email-Liste auszutragen. Daraufhin wirst Du eine
Bestätigungsemail erhalten, die Du noch mal kurz beantworten musst ( ohne
weiteren Inhalt )! Dann solltest Du keine Emails von der Liste mehr
erhalten.

Hi Gunnar , I just tried to translate you.

Mit freundlichen Gruessen / Best regards

Manfred Beilfuss




   
   
Gunnar 
   
Hjalmarsson  An: [EMAIL PROTECTED] 
  
<[EMAIL PROTECTED]Kopie:   

ar.cc>   Thema:  Re: """[EMAIL PROTECTED]""" aus Eurer 
Verteiung nehmen! 
   
   
29.10.2004 
   
09:13  
   
   
   
   
   




FYI I just sent this message:

 Original Message 
Subject: Re: Bitte schreibe mir in Deutsch !!
Date: Fri, 29 Oct 2004 09:09:42 +0200
From: Gunnar Hjalmarsson
To: Spikema (Sonja Klenner)

Dear Sonja,

Thanks for your note. I did understand most of what you wrote (studied
some German once in school), but please excuse me for still replying in
English.

I'm truly sorry to hear about the death of your husband.

I made an attempt to help you by unsubscribing the address
[EMAIL PROTECTED] from the [EMAIL PROTECTED] mailing list (see
below). That should have resulted in a confirmation message, and if you
just reply to that, you should stop receiving messages from the list.

Hope that will help.

Kind regards,

Gunnar


 Original Message 
Subject: Unsubscribe request
Date: Fri, 29 Oct 2004 08:53:31 +0200
From: Gunnar Hjalmarsson <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]


--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

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








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




Re: Antwort: Re: """Wallbanger@t-online.de""" aus Eurer Verteiung nehmen!!!!!

2004-10-29 Thread Gunnar Hjalmarsson
Manfred Beilfuss wrote:
Hi Gunnar , I just tried to translate you.
Schönen Dank! :)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: xml parsing

2004-10-29 Thread Philipp Traeder
On Thursday 28 October 2004 10:56, E.Horn wrote:

Good morning,

> this gives me a DTD as output.

DTD?
As in the kind of document that describes XML files?
If yes, an XML Parser might be the wrong tool for parsing this kind of file.
Could you give us an example?

> My problem is I want to parse this output!
> But how can ich give it to the second code that this parses the result
> of (sub_daten_einlesen)
> I hope someone understands my question ;-)

[..snipped some code...]
>
>
> $url1 =daten_einlesen();
> $doc = get $url1;
> print $doc;

>
> #!/xprog/bin/perl
>
> # use module
> use XML::Simple;
> use Data::Dumper;
>
> # create object
> $xml = new XML::Simple;
>
> # read XML file
> $data = $xml->XMLin("which path???");

If the output you want to parse is stored in $doc, you should be able to pass 
it directly to XML::Simple:

  my $data = $xml->XMLin($doc);

HTH,

Philipp

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




parse xml

2004-10-29 Thread E.Horn
geben Sie ein gtpprotein ein
ras

http://www.ncbi.nlm.nih.gov/entrez/query/DTD/egquery.dtd";>






ras



 
  pubmed
  PubMed
  27832
  Ok
 

 
  pmc
  PMC
  6921
  Ok
 

.





that is the output!
I ONLY want to have somethimg like this: Pubmed  27832

Pmc 6921



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




Append on top

2004-10-29 Thread Rajesh Dorairajan
Does anyone know of a way to open a file in append mode and append on top of
the file? 

Thanks in Advance,

--Rajesh 


RE: Append on top

2004-10-29 Thread Sreedhar . Kalkunte-Venkatachala
open(MYNAME,">>a.txt");


-Original Message-
From: Rajesh Dorairajan [mailto:[EMAIL PROTECTED]
Sent: 29 October 2004 02:12
To: Perl-Beginners ([EMAIL PROTECTED])
Cc: Rajesh Dorairajan
Subject: Append on top


Does anyone know of a way to open a file in append mode and append on top of
the file? 

Thanks in Advance,

--Rajesh 

Visit our website at http://www.ubs.com

This message contains confidential information and is intended only
for the individual named.  If you are not the named addressee you
should not disseminate, distribute or copy this e-mail.  Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses.  The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission.  If
verification is required please request a hard-copy version.  This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.


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




RE: Append on top

2004-10-29 Thread arjun.mallik

This mode will append text at the bottom not at the top.

Arjun


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Friday, October 29, 2004 2:45 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Append on top


open(MYNAME,">>a.txt");


-Original Message-
From: Rajesh Dorairajan [mailto:[EMAIL PROTECTED]
Sent: 29 October 2004 02:12
To: Perl-Beginners ([EMAIL PROTECTED])
Cc: Rajesh Dorairajan
Subject: Append on top


Does anyone know of a way to open a file in append mode and append on
top of the file?

Thanks in Advance,

--Rajesh

Visit our website at http://www.ubs.com

This message contains confidential information and is intended only
for the individual named.  If you are not the named addressee you
should not disseminate, distribute or copy this e-mail.  Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses.  The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission.  If
verification is required please request a hard-copy version.  This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.


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





Confidentiality Notice

The information contained in this electronic message and any attachments to this 
message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged 
information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.

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




Newbie: Perl Vs Shell

2004-10-29 Thread Durai raj
Hello All,
 
  Anyone can explain the difference between Perl and Shell scripts?
 
Regards,
Durai.
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.783 / Virus Database: 529 - Release Date: 10/27/2004


-
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.

Re: Append on top

2004-10-29 Thread Ing. Branislav Gerzo
Rajesh Dorairajan [RD], on Thursday, October 28, 2004 at 18:11 (-0700)
thoughtfully wrote the following:

RD> Does anyone know of a way to open a file in append mode and append on top of
RD> the file?

I don't think it is possible. You have to read source file, and after
print your results to new file (open through >) and append old file
through >>

-- 

 ...m8s, cu l8r, Brano.

[Confucius Says: Man who has woman on ground has piece on earth!]



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




RE: Newbie: Perl Vs Shell

2004-10-29 Thread arjun.mallik

Shell scripting is native to the shell in which u right them and are not
portable  more imp is difficult to implement even simple logic ..but are
very fast as they are native to OS.

,where as  Perl scripts are inter operable and a bit easy to write and
debug] compared to shell scripts.

This as per my under standing

Arjun


-Original Message-
From: Durai raj [mailto:[EMAIL PROTECTED]
Sent: Friday, October 29, 2004 3:01 PM
To: [EMAIL PROTECTED]
Subject: Newbie: Perl Vs Shell


Hello All,

  Anyone can explain the difference between Perl and Shell scripts?

Regards,
Durai.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.783 / Virus Database: 529 - Release Date: 10/27/2004


-
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.



Confidentiality Notice

The information contained in this electronic message and any attachments to this 
message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged 
information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.

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




RE: Append on top

2004-10-29 Thread NYIMI Jose \(BMB\)


> -Original Message-
> From: Ing. Branislav Gerzo [mailto:[EMAIL PROTECTED] 
> Sent: Friday, October 29, 2004 11:36 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Append on top
> 
> 
> Rajesh Dorairajan [RD], on Thursday, October 28, 2004 at 
> 18:11 (-0700) thoughtfully wrote the following:
> 
> RD> Does anyone know of a way to open a file in append mode 
> and append 
> RD> on top of the file?
> 
> I don't think it is possible. You have to read source file, 
> and after print your results to new file (open through >) and 
> append old file through >>

Or no need to open the file:

use Tie::File;
tie @array, 'Tie::File', filename or die "...";
unshift @array, "new recs"; #will append on top
untie @array;

HTH,
José.


 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. This email is not intended to create or affect any 
contractual arrangements between the parties.
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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




Get all mail addresses from a domain

2004-10-29 Thread Eva Perales Laguna
Hello,

I use the Net::SMTP module to check if a mail address is present
in a domain. I do something like this:

   my $smtp = new Net::SMTP($domain);
my $matches = $smtp->verify($usermane);

But I would like to get all the addresses in that domain.
Someone can help me? 

Thanks!
Eva


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




Re: parse xml

2004-10-29 Thread Traeder, Philipp
On Friday 29 October 2004 10:44, E.Horn wrote:
> geben Sie ein gtpprotein ein
> ras
> 
>  "http://www.ncbi.nlm.nih.gov/entrez/query/DTD/egquery.dtd";>
>
> 
> 
>
> 
>
> ras
>
> 
>
>  
>   pubmed
>   PubMed
>   27832
>   Ok
>  
>
>  
>   pmc
>   PMC
>   6921
>   Ok
>  
>
> .
>
> 
>
> 
>
> that is the output!
> I ONLY want to have somethimg like this: Pubmed  27832
>
> Pmc 6921

In this case, take a look at the thread "how to parse this xml file" which 
started yesterday - the XML schema seems to be the same.

If you want to combine this code with the code you posted earlier, just take 
the string you received from the URL (it was called $doc, I think) and take 
it as input param for XMLin() (see my last mail).

BTW: Is this some kind of programming request - it seems as if at least 
Franklin and you are trying to write the same script ;-)

Philipp

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




re parse xml to Franklin

2004-10-29 Thread E.Horn
Ok!
So Franklin, how does your parser look like?
Is this really the same homepage you parse?
Where do you come from ;-) perhaps you sit in the room next
door? joking...?!


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




Re: Newbie: Perl Vs Shell

2004-10-29 Thread Chris Devers
On Fri, 29 Oct 2004, Durai raj wrote:

>   Anyone can explain the difference between Perl and Shell scripts?

They're completely separate languages.

On Unix systems, a "shell" is a program that receives input and sends 
results down to the kernel to be executed, thus the name "shell" -- it's 
an easier way to work than trying to talk to the kernel directly. Common 
shells include bash, ksh, zsh, tcsh, csh, and sh. The last one is called 
the Bourne shell; it is the original and most others resemble it. A 
series of shell statements that could otherwise be run directly at the 
command line prompt can also be saved as a shell script and run that 
way, much like a DOS batch script. These scripts are typically written 
in the Bourne shell (sh), because that's the one most likely to be 
installed on any given Unix system, but shell scripts can be written in 
any shell language. People will look at you funny if you write them 
using the csh shell, but even that one can be used :-)

On the other hand, Perl is a programming language that was designed with 
ideas from many places, including the different Unix shells, languages 
like C, Basic & Lisp, and Unix system commands like Sed and Awk. A lot 
of Perl's core functions look and act like well known shell commands -- 
grep, chmod, etc -- but this is only to help make Perl easy to learn for 
someone already familiar with those commands. 

Perl is separate from the Unix shells. You can have some overlap -- a 
shell script can make use of all sorts of programs, including perl, and 
a Perl script can run shell commands with system( ... ) or `...` -- but 
in general, well written shell scripts don't need Perl and well written 
Perl scripts don't need external shell commands. 

Clearer?


-- 
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/

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




RE: Append on top

2004-10-29 Thread Bob Showalter
Rajesh Dorairajan wrote:
> Does anyone know of a way to open a file in append mode and append on
> top of the file?

No, because that's not what "append mode" means. To insert data anywhere but
at the end, you have to rewrite the file contents from the point of
insertion forward. Or, you need to write the new data plus the old file
contents to a temporary file and then move it back over the old file.

Jose's Tie::File suggestion is probably the easiest way to go.

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




RE: Get all mail addresses from a domain

2004-10-29 Thread Bob Showalter
Eva Perales Laguna wrote:
> Hello,
> 
> I use the Net::SMTP module to check if a mail address is present
> in a domain. I do something like this:
> 
>my $smtp = new Net::SMTP($domain);
>   my $matches = $smtp->verify($usermane);
> 
> But I would like to get all the addresses in that domain.

Lots of folks turn off VRFY and EXPN, for obvious reasons.

SMTP is not a directory service. You would need to query a directory
service, like LDAP.

I assume your purposes are wholly pure and honest :~)

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




Re: Assigning regexpression to a variable

2004-10-29 Thread John W. Krahn
Prabahar Mosas wrote:
On Fri, 29 Oct 2004 John W.Krahn wrote :
Prabahar Mosas wrote:
specimen coding
**
$value = 2422;  $reg = '/\d/';
The slashes (/) are the delimiters for the match operator, they
are not a part of the regular expression, just like the quotes
(') delimit the string but are not a part of it.  Your "regular
expression" says match a '/' character followed by a '\d' character
followed by a '/' character.
>
> I agree your point.  But that is simple regular expression.
> When I assign complex regular expressions into a variable it won't
> assign.
>
> eg $regex = 's/[A-Z]/[a-z]/g';
That is matching every *single* character in the range A-Z and replacing 
*each* *character* with the *string* '[a-z]'.

>$regex =  's/\r//g';
>$regex = '/(^[^a-z])|/|(\.\.)/i'
>   For this case What I need to do for that Mail me. Because this Problem is 
> one of the barrier in my project.

It looks like you may be confused between a regular expression, which is 
similar to a string, and the match, substitution and transliteration 
operators, two of which use regular expressions.  Have you read some of the 
documentation on regular expressions and strings?

perldoc perlrequick
perldoc perlretut
perldoc perlre
perldoc perlop
perldoc perlreref
If you still think you need to do the above then:
perldoc -q "How do I match a pattern that is supplied by the user"
perldoc -f eval

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Printing to a file

2004-10-29 Thread Zeus Odin
I could see this thread coming 2 months ago. Does anyone have any pent-up
frustrations?
:-)

I think this list is the BEST list I have ever read ... not that I have read
many lists. However, any list can be improved. The improvements I would
suggest have to do with editorializing and patience:

First, editorializing--definition here
http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=editorialize. If
you find yourself making comments about code--after all, it's all about the
code--that is the purpose of this list. This is and should be supported ad
infinitum and ad nauseum. On the other hand, if you find yourself making
comments about the poster in general, I think it is a sign of trouble. Who
is it for me to say that what one programmer tried in a day is not equal to
what a lesser programmer tried in a week?

Charles Clarkson, Randall Schwartz, and John Krahn (I'm only naming three.
Apologies to those I omitted. Whatever happened to Drieux?) are some of the
most respected lurkers in this forum. I try to read their posts whenever I
can. I am sure that a day of their effort would go a long way. But so what?
Not many can compare their abilities to the "highly seasoned."

There are much differing abilities of all those that post to this forum. I
recently rewrote something I first wrote in Perl when I was just starting
out. The code went from 100 lines to only 20.

What I am trying to say is if you find yourself getting ready to post
something that is not talking explicitly about code, chances are it is
better left unsaid (unwritten). I think we should stick to: what did you
try; can I see your code; this is where your problem is; an alternate
solution is These are just my opinions. Yours might vary.

Second, patience. We should all be more patient. Keep in mind that this is a
global group. This forum is in English but English is not the native
language of many here. Many translate directly from their native tongue into
English. Sometimes desired nuances are lost or undesired ones gained. It can
be taken differently and offensively by some.

There have been many posts I have read here that have rubbed me the wrong
way. What did I do? I immediately moved on to the next post or thread.
Otherwise, you spend time editorializing. That's bad.

Everyone here is subject to criticism including me. If you don't like that,
then please do not post anything here. You are still free to read. When in
doubt, discretion is the better part of valor.

Just my 2 cents. I hope I didn't offend any as that was not my intent. Now
let's get back to business. Well, actually this is pleasure for me.

Thanks,
ZO

<[EMAIL PROTECTED]> wrote in message...
> I agree, Gunnar is mean.  Mean people suck!
>
> derek



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




Re: Append on top

2004-10-29 Thread Mandar Rahurkar
read the file. Rewrite ur data into the file followed by original data. easy way..

Mandar

 Original message 
>Date: Thu, 28 Oct 2004 18:11:54 -0700
>From: "Rajesh Dorairajan" <[EMAIL PROTECTED]>  
>Subject: Append on top  
>To: "Perl-Beginners ([EMAIL PROTECTED])" <[EMAIL PROTECTED]>
>Cc: "Rajesh Dorairajan" <[EMAIL PROTECTED]>
>
>Does anyone know of a way to open a file in append mode and append on top of
>the file? 
>
>Thanks in Advance,
>
>--Rajesh 
---
Mandar Rahurkar
ECE,   UIUC
---

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




RE: Newbie: Perl Vs Shell

2004-10-29 Thread Thomas Bätzler
Chris Devers <[EMAIL PROTECTED]> claimed:
[...]
> well 
> written shell scripts don't need Perl and well written Perl 
> scripts don't need external shell commands. 

I think that's the "ivory tower" point of view. Down
here in the trenches, it's more like "a well-written
Perl script uses shell commands where it makes sense".
Obviously the art is in knowing where it makes sense
and where not.

Cheers,
Thomas

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




RE: Append on top

2004-10-29 Thread NYIMI Jose \(BMB\)


> -Original Message-
> From: Mandar Rahurkar [mailto:[EMAIL PROTECTED] 
> Sent: Friday, October 29, 2004 3:18 PM
> To: Rajesh Dorairajan; Perl-Beginners ([EMAIL PROTECTED])
> Subject: Re: Append on top
> 
> 
> read the file. Rewrite ur data into the file followed by 
> original data. easy way..
> 

I'm not convinced this approach will do the job.
Please send an excerpt code ...

José.


 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. This email is not intended to create or affect any 
contractual arrangements between the parties.
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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




Re: Printing to a file

2004-10-29 Thread John W. Krahn
Zeus Odin wrote:
Charles Clarkson, Randall Schwartz, and John Krahn (I'm only naming three.
You probably meant Randal Schwartz (one "l".)   :-)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Append on top

2004-10-29 Thread brian . barto
This is the way I would do it, however my code has been subject to criticism
more that once in the past :)

open (FILE, ";
close (FILE);
$new_data = "This is my new line that I am going to put at the top\n";
unshift (@file, $new_data);
open (FILE, ">myfile.dat") or die;
print FILE @file;
close (FILE);

-Original Message-
From: NYIMI Jose (BMB) [mailto:[EMAIL PROTECTED]
Sent: Friday, October 29, 2004 9:34 AM
To: Mandar Rahurkar; Rajesh Dorairajan; [EMAIL PROTECTED]
Subject: RE: Append on top




> -Original Message-
> From: Mandar Rahurkar [mailto:[EMAIL PROTECTED] 
> Sent: Friday, October 29, 2004 3:18 PM
> To: Rajesh Dorairajan; Perl-Beginners ([EMAIL PROTECTED])
> Subject: Re: Append on top
> 
> 
> read the file. Rewrite ur data into the file followed by 
> original data. easy way..
> 

I'm not convinced this approach will do the job.
Please send an excerpt code ...

José.


 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is
confidential and/or protected by intellectual property rights and are
intended for the sole use of the recipient(s) named above. This email is not
intended to create or affect any contractual arrangements between the
parties.
Any use of the information contained herein (including, but not limited to,
total or partial reproduction, communication or distribution in any form) by
other persons than the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either
by telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our
website at http://www.proximus.be or refer to any Proximus agent.


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


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




regex matching in a nested loop

2004-10-29 Thread Jason Wozniak
I wrote the following as a quick script to find all files on the system
that contain any hard coded passwords for our database.  For testing
purposes I used a file called testing123 in my find string, so as not to
search the entire directory tree for each test.  The problem I'm having
lies in the while loop of my search subroutine.  If I use a for loop to
iterate over all the passwords for each line of the input file, $_ is
overwritten with a numeric value before the matching can take place, so
I can't match the line I'm reading in from the file.  If I get rid of
the for loop and use a counter like $count to iterate through my array,
the file I'm reading often has more lines then the array, so the looping
gets messy, having to reset the counter each time through the array for
each line in the file, and I can't use shift of course, because I need
to iterate through the array multiple times.  So I'm hoping maybe
someone might know a more elegant solution to my problem?
 
#!/usr/bin/perl -w
# Author: Jason Wozniak
# Purpose: To find any hard coded passwords in shell scripts, so they
can be changed.
 
use File::Finder;
my $prod_pass_file = "/u01/app/oracle/orausers.prod";
my $test_pass_file = "/u01/app/oracle/orausers.test";
my $tmpfile = "/u01/app/oracle/hdpjfw_scripts/tempfile.tmp";
my $user;
my $pass;
my $newline;
my $count = 0;
my @passwords;
 
print "This program will search for passwords in all regular text files
in the directory specified\n";
print "for all passwords listed in either $prod_pass_file or
$test_pass_file\n";
print "depending on the database specified\n";
print "Enter a directory to search\n";
chomp(my $search_dir = );
my @file_list = File::Finder->name('testing123')->in($search_dir);
#foreach (@file_list) {
#my $vartest = shift(@file_list);
#print "my file list is $vartest\n";
#}
 
print "Enter Database SID\n";
chomp(my $database = );
my $passfile =
($database eq "P01") ? $prod_pass_file :
($database eq "R01") ? $prod_pass_file :
($database eq "T01") ? $test_pass_file :
($database eq "X01") ? $prod_pass_file :
($database eq "D01") ? $test_pass_file : "Invalid";
if ($passfile eq "Invalid") {
  print "Invalid database SID\n";
  exit;
  }
else {
  open (PASSFILE, "<$passfile")
or die "Could not open $passfile: $!\n";
  }
 
while () {
  ($user, $pass, $newline) = split( /:/, $_);
  $passwords[$count] = $pass;
  $count++;
  }
 
open (TMPFILE, ">$tmpfile")
  or die "Could not open temporary file: $!\n";
 
foreach $file_list (@file_list) {
&search();
  }
 
close TMPFILE;
 
sub search {
  my $file = shift(@file_list);
  open (FILE, "<$file")
or die "Could not read $file: $!\n";
  print "$file opened\n";
  while () {
for (0..$#passwords) {
  if (/$passwords[$_]/) {
print "Match found!\n";
print TMPFILE $file
  or die "Could not write to file: $!\n";
}
  }
}
}
 
 
Jason Wozniak
Systems Administrator,
Oracle DBA
Henkels & McCoy
985 Jolly Road
Blue Bell PA, 19422
 
 


RE: Newbie: Perl Vs Shell

2004-10-29 Thread Jenda Krynicky
From: <[EMAIL PROTECTED]>
> Shell scripting is native to the shell in which u right them and are
> not portable  more imp is difficult to implement even simple logic
> ..but are very fast as they are native to OS.

Actually no. They are generaly not very fast. The reason is that the 
shell interpreter needs to create a new process for each and every 
commend you specify in the script and usualy parses and executes the 
script line by line. Which means that if you have a loop in the 
script the interpreter will parse the lines within the loop over and 
over again.

So as soon as the script gets even a little bit more complex it gets 
much slower than a Perl script would be.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




RE: Append on top

2004-10-29 Thread Jenda Krynicky
From:   [EMAIL PROTECTED]
> This is the way I would do it, however my code has been subject to
> criticism more that once in the past :)
> 
> open (FILE, " @file = ;
> close (FILE);
> $new_data = "This is my new line that I am going to put at the top\n";
> unshift (@file, $new_data); open (FILE, ">myfile.dat") or die; print
> FILE @file; close (FILE);

:-)

This is definitely a workable solution, there are just a few things 
to keep in mind.

1)This would mean that the whole file is read into the memory.
2)This would force Perl to search for end-of-lines and create an 
array.
3) You open the file in text mode in both cases. This may change the 
type of newlines in the file!

So it's fine for small files, but not so great for bigger ones.

If you want something more efficient you might try something like 
this:

open NEWFILE, '>', 'myfile.dat.tmp' 
  or die "Can't create myfile.dat.tmp: $^E\n";
print NEWFILE "the new stuff to put on top\n";
...

open OLDFILE, '<', 'myfile.dat'
  or die "Can't open the original file myfile.dat: $^E\n";
binmode(OLDFILE);
binmode(NEWFILE);
my $buff;
print NEWFILE $buff 
while (read OLDFILE, $buff, 8*1024);
close NEWFILE;
close OLDFILE;
rename 'myfile.dat.tmp' => 'myfile.dat';

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




RE: Newbie: Perl Vs Shell

2004-10-29 Thread Chris Devers
On Fri, 29 Oct 2004, Thomas Bätzler wrote:

> Chris Devers <[EMAIL PROTECTED]> claimed:
> [...]
> > well written shell scripts don't need Perl and well written Perl 
> > scripts don't need external shell commands.
> 
> I think that's the "ivory tower" point of view. Down here in the 
> trenches, it's more like "a well-written Perl script uses shell 
> commands where it makes sense". Obviously the art is in knowing where 
> it makes sense and where not.

I was trying to be specific there. 

I'm not saying that it's never legitimate for a Perl script to run a 
system( ... ) call or execute something in `backticks`. Everything has a 
place, including those tools. 

I'm specifically talking about things like this in Perl:

  @files = `ls -1`;
  $timestamp = `date`;

Constructs like this can easily be done in pure Perl. 

Likewise, shell scripts with lines like this:

  grep 'foo' logfile \
  | perl -pe '$l=$_; ($s=$l) =~ m/^([0-9])+/; print scalar localtime $s, " ";' \
  | sed -e 's#\( 200[0-9]\) 1[0-9]*#\1#' -e 's#\(.*\)#   \1#' \
  >> $htmllog

Are complex enough that it's probably worth considering rewriting the 
whole thing in Perl. Perl is a much bigger program than most of the 
standard shell tools, so a script like this is probably slower than it 
needs to be. Moreover, to get this down to a reasonable line length, it 
uses an obtuse style that would really be more readable as a Perl script 
spread out over several more lines. In the long run, the pure Perl 
version would be easier to maintain, even if in the short term it seems 
more expedient to kludge in a tricky bit in the shell script using a 
single call to Perl, then reverting to shell tools afterwards. 

What's expedient isn't always a good idea in the long term.


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


using file before and after when in foreach loop

2004-10-29 Thread Murphy, Ged (Bolton)
Hi all.

I'm using a foreach loop to iterate through an array and print out HTML code
related to each value.
However in my HTML code I would also like to make links to the previous
array item and next array item.

The previous item is simple to do, but I'm struggling to think of a way of
getting the next item.

Can anyone give me any pointers?

Here is my snippet of code so far:

#
#  write picture page html code
#
my $prev;
foreach (@files) {
my($start,$end) = split/\./, $_;
open PICPAGE, ">$dir\/$start.html" or die "Can't open: $!";
print PICPAGE print_pic_page($_, $prev, 'next');
close PICPAGE;
$prev = "$dir\/$start.html"
}


Thanks.


--
**apologies for the below disclaimer. It's tagged on at the mail server.**

--



The information contained in this message or any of its
attachments is confidential and is intended for the exclusive
use of the addressee. The information may also be legally
privileged. The views expressed may not be company policy,
but the personal views of the originator. If you are not the
addressee, any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited.
If you have received this message in error, please contact
[EMAIL PROTECTED] 
 and then delete this message. 

Exide Technologies is an industrial and transportation battery
producer and recycler with operations in 89 countries.
Further information can be found at www.exide.com



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




Re: using file before and after when in foreach loop

2004-10-29 Thread Jeff Eggen
>>> "Murphy,  Ged (Bolton)" <[EMAIL PROTECTED]> 29/10/2004
9:02:56 am >>>
>The previous item is simple to do, but I'm struggling to think of a
way of
>getting the next item.

You could just change your foreach line to a standard for loop:

for ( my $index = 0; $index <= $#files; $index++ )
{
}

And then just use $files[$index] wherever you use $_ below, and then
you can refer to as many other elements in the array as you like with
"$index + 1", "$index - 1", etc.

Hope this helps,

Jeff Eggen
IT Programmer Analyst
Saskatchewan Government Insurance
Ph (306) 751-1795
email [EMAIL PROTECTED]
DISCLAIMER*
This e-mail and any files transmitted with it are confidential and intended solely for 
the use of the individual or entity to whom they are addressed.  If you are not the 
named addressee, please notify the sender immediately by e-mail if you have received 
this e-mail by mistake and delete this e-mail from your system. If you are not the 
intended recipient you are notified that using, disclosing, copying or distributing 
the contents of this information is strictly prohibited.
DISCLAIMER*

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




Re: using file before and after when in foreach loop

2004-10-29 Thread Roberto Alamos
or better you can do

for(0.$#files) {
 $prev = $files[$_-1];
 $next = $files[$_+1];
}

where $#files is the array's length - 1.

Bye
On Fri, 29 Oct 2004 09:14:25 -0600, Jeff Eggen <[EMAIL PROTECTED]> wrote:
> >>> "Murphy,  Ged (Bolton)" <[EMAIL PROTECTED]> 29/10/2004
> 9:02:56 am >>>
> >The previous item is simple to do, but I'm struggling to think of a
> way of
> >getting the next item.
> 
> You could just change your foreach line to a standard for loop:
> 
> for ( my $index = 0; $index <= $#files; $index++ )
> {
> }
> 
> And then just use $files[$index] wherever you use $_ below, and then
> you can refer to as many other elements in the array as you like with
> "$index + 1", "$index - 1", etc.
> 
> Hope this helps,
> 
> Jeff Eggen
> IT Programmer Analyst
> Saskatchewan Government Insurance
> Ph (306) 751-1795
> email [EMAIL PROTECTED]
> DISCLAIMER*
> This e-mail and any files transmitted with it are confidential and intended solely 
> for the use of the individual or entity to whom they are addressed.  If you are not 
> the named addressee, please notify the sender immediately by e-mail if you have 
> received this e-mail by mistake and delete this e-mail from your system. If you are 
> not the intended recipient you are notified that using, disclosing, copying or 
> distributing the contents of this information is strictly prohibited.
> DISCLAIMER*
> 
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
>

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




Why is not "sub" necessary? What is the difference: block and expression?

2004-10-29 Thread Siegfried Heintze
I'm trying to understand the map function in perl and have been studying
David's response to my earlier query.

When David calls his iterate function, why does he not need to use the
keyword "sub"? Apparently he is passing a function by reference. Is this a
block or an expression? The camel book says map takes a block or an
expression and I don't understand the difference.

Also, can someone elaborate on his use of prototyping here when he defines
function iterate? I don't understand the "&@". 

And, what about the use of the keyword "for". Should that not be "foreach"?
The code works so I guess it is correct.


Lastly, I tried to rewrite the code so I could understand it. Why does not
this work?

sub iterate{ 
  my $code = shift;
  print " begin function iterate\n"; 
  foreach $x (@_) { &$code($x) ; }
  print " end function iterate\n"; 
}
iterate ({ print "Hello $_\n" }, @data);

Here is what I get:
cd c:/OpenPerlIDE_1.0.11.409/
perl test_expression.pl
Not a CODE reference at test_expression.pl line 5.

Hello 

 begin function iterate


Compilation exited abnormally with code 255 at Fri Oct 29 10:27:02

I tried removing the comma from the call to iterate, but that did not help.

  Thanks,
 Siegfried


> On Sun, 10 Oct 2004 14:30:32 -0600, Siegfried Heintze
<[EMAIL PROTECTED]> wrote:
> > 
> > The map and the sort statements are strange. Why don't they require a 
> > comma between the first and second arguments?
> 
> They are not special, they are just using a special semantic built into
perl.
> 
> Consider the following:
>


> sub iterate(&@)
> {
>   my $code = shift;
>   &$code for @_;
> }
> 
> @data = ( "jack", "jill", "jenny" );
> 
> iterate { print "Hello $_\n" } @data
>


> 
> The "iterate" function takes a CODE reference and an ARRAY of stuff (same
as MAP and GREP and SORT).  It will then blindly iterate over the array of
stuff and invoke the code for each element.
> 
> The basic rule is, a BLOCK OF CODE does not require a comma after it,
because it is self-enclosing (ie, it has braces). 
> 
> Consider then, that since 'map {xx} @data' is actually parsing {xx} as a
code reference, the same way 'my $prog = { some code}' does, you can also do
> 
> sub sortfilter($$){
> stuff
> }
> 
> sort \&sortfilter, @data
> 
> or even
> 
> sub special_sort(&@)
> {
>  my $sort_func = shift;
>  sort  $sort_func, @_
> }
> 
> You should probably read more on anonymous subroutines and code blocks.
(and even closures).
> 
> Cheers.
> David
> 
> > 
> > Thanks,
> >Siegfried


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




RE: Newbie: Perl Vs Shell

2004-10-29 Thread Chris Devers
On Fri, 29 Oct 2004, Jenda Krynicky wrote:

> Actually no. They are generaly not very fast. The reason is that the 
> shell interpreter needs to create a new process for each and every 
> commend you specify in the script [...]

Is this true even for built in shell commands? For example, commands 
like cd, echo, export, kill, test, etc are all built in to Bash -- does 
an external process run whenever you invoke one of these? 

 

-- 
Chris Devers

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




Re: Why is not "sub" necessary? What is the difference: block and expression?

2004-10-29 Thread Gunnar Hjalmarsson
Siegfried Heintze wrote:
I'm trying to understand the map function in perl and have been studying
David's response to my earlier query.
When David calls his iterate function, why does he not need to use the
keyword "sub"?
Because he used prototypes instead.
Also, can someone elaborate on his use of prototyping here when he defines
function iterate? I don't understand the "&@".
They make the function expect a coderef followed by a list.
And, what about the use of the keyword "for". Should that not be "foreach"?
Those are synonymous (at least as keywords...).
Lastly, I tried to rewrite the code so I could understand it. Why does not
this work?
sub iterate{ 
  my $code = shift;
  print " begin function iterate\n"; 
  foreach $x (@_) { &$code($x) ; }
  print " end function iterate\n"; 
}
iterate ({ print "Hello $_\n" }, @data);
This is one way to make it "work":
sub iterate {
my $code = shift;
print " begin function iterate\n";
foreach my $x (@_) { &$code($x) ; }
print " end function iterate\n";
}
iterate ( sub { print "Hello $_[0]\n" }, @data);
--^^^^
'sub' makes the block a coderef, and since you are setting $x in your 
foreach loop, $_ is not set.

An alternative:
sub iterate(&@) {
my $code = shift;
print " begin function iterate\n";
foreach my $x (@_) { &$code($x) ; }
print " end function iterate\n";
}
iterate { print "Hello $_[0]\n" } @data;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Append on top

2004-10-29 Thread Ajey Kulkarni


>>> while (read OLDFILE, $buff, 8*1024);

A quick qn. :) Y is 8*1024 being mentioned here? Are you just
word-aligning or something else?

regards
-Ajey

On Fri, 29 Oct 2004, Jenda Krynicky
wrote:


> From: [EMAIL PROTECTED]
> > This is the way I would do it, however my code has been subject to
> > criticism more that once in the past :)
> >
> > open (FILE, " > @file = ;
> > close (FILE);
> > $new_data = "This is my new line that I am going to put at the top\n";
> > unshift (@file, $new_data); open (FILE, ">myfile.dat") or die; print
> > FILE @file; close (FILE);
>
> :-)
>
> This is definitely a workable solution, there are just a few things
> to keep in mind.
>
> 1)This would mean that the whole file is read into the memory.
> 2)This would force Perl to search for end-of-lines and create an
> array.
> 3) You open the file in text mode in both cases. This may change the
> type of newlines in the file!
>
> So it's fine for small files, but not so great for bigger ones.
>
> If you want something more efficient you might try something like
> this:
>
> open NEWFILE, '>', 'myfile.dat.tmp'
>   or die "Can't create myfile.dat.tmp: $^E\n";
> print NEWFILE "the new stuff to put on top\n";
> ...
>
> open OLDFILE, '<', 'myfile.dat'
>   or die "Can't open the original file myfile.dat: $^E\n";
> binmode(OLDFILE);
> binmode(NEWFILE);
> my $buff;
> print NEWFILE $buff
>   while (read OLDFILE, $buff, 8*1024);
> close NEWFILE;
> close OLDFILE;
> rename 'myfile.dat.tmp' => 'myfile.dat';
>
> Jenda
> = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
> When it comes to wine, women and song, wizards are allowed
> to get drunk and croon as much as they like.
>   -- Terry Pratchett in Sourcery
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>


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




Re: Get all mail addresses from a domain

2004-10-29 Thread Chasecreek Systemhouse
On Fri, 29 Oct 2004 08:42:14 -0400, Bob Showalter
<[EMAIL PROTECTED]> wrote:
> Eva Perales Laguna wrote:
> > But I would like to get all the addresses in that domain.
> 
> Lots of folks turn off VRFY and EXPN, for obvious reasons.


Besides, VRFY and EXPN do not prove that an e-mail exists at any
particular domain.


With all the apmmers in the world mail admins are taking drastic steps
to stop spammers.

-- 
WC -Sx- Jones
http://youve-reached-the.endoftheinternet.org/

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




each character in a string

2004-10-29 Thread mk76
Hi All,
I have to write a code wherein I have to access each character in a
string and compare it with '-'

$_ = $seq1[0];
while(/./g) {
 if($1 eq '-') {
$res1[0] .= '-';
 }
 else {
$res1[0] = "A";
 }
}

I have initialised $_ with the string in which I have to search. Now I
know that the while loop will read each and every character in the
string. I just need to get that character read to make the comparison. I
know $1 doesnt work because it is not :) Where is the value returned or
how can I assign a variable the value of the condition in the while loop ?

Thanks,
Manas.

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




easy way to add element to array

2004-10-29 Thread brian . barto
Hi. I'm working with an array that i'm pushing values on to, but I don't
want there to be any duplicates. Is there a perl function of an easy way to
check if an array already contains a value before I push that value on to
it?
 
Thanks,
Brian


Re: each character in a string

2004-10-29 Thread Ajey Kulkarni
It will...

#!/usr/bin/perl

my $var = "--  hellohowareyou-";


$_ = $var;
while (/(.)/g) { # . is never a newline here
# do something with $1
if($1 eq '-') {
printf "HELLO";
}
else {
printf "HI";
}

}


On Fri, 29 Oct 2004 [EMAIL PROTECTED] wrote:

> Hi All,
> I have to write a code wherein I have to access each character in a
> string and compare it with '-'
>
> $_ = $seq1[0];
> while(/./g) {
>  if($1 eq '-') {
> $res1[0] .= '-';
>  }
>  else {
> $res1[0] = "A";
>  }
> }
>
> I have initialised $_ with the string in which I have to search. Now I
> know that the while loop will read each and every character in the
> string. I just need to get that character read to make the comparison. I
> know $1 doesnt work because it is not :) Where is the value returned or
> how can I assign a variable the value of the condition in the while loop ?
>
> Thanks,
> Manas.
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>


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




RE: easy way to add element to array

2004-10-29 Thread Bob Showalter
[EMAIL PROTECTED] wrote:
> Hi. I'm working with an array that i'm pushing values on to, but I
> don't want there to be any duplicates. Is there a perl function of an
> easy way to check if an array already contains a value before I push
> that value on to it?

First consider whether you should be using a hash.

If you still want to use an array, the Tie::File::Array module will do the
trick.


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




RE: easy way to add element to array

2004-10-29 Thread Bob Showalter
Bob Showalter wrote:
> If you still want to use an array, the Tie::File::Array module will
> do the trick.

Duh, that should be "Tie::Array::Unique". Sorry 'bout that.

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




Re: each character in a string

2004-10-29 Thread Gunnar Hjalmarsson
[EMAIL PROTECTED] wrote:
I have to write a code wherein I have to access each character in a
string and compare it with '-'
$_ = $seq1[0];
while(/./g) {
 if($1 eq '-') {
$res1[0] .= '-';
 }
 else {
$res1[0] = "A";
 }
}
I have initialised $_ with the string in which I have to search. Now I
know that the while loop will read each and every character in the
string. I just need to get that character read to make the comparison. I
know $1 doesnt work because it is not :) Where is the value returned or
how can I assign a variable the value of the condition in the while loop ?
As Ajey showed, $1 does work provided that you use capturing 
parentheses, or you can use $& (but read the warning in "perldoc perlre" 
if you consider the latter).

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: easy way to add element to array

2004-10-29 Thread brian . barto
Though about using a hash but I don't have a need for a Key/Value
combination. I just need a list without duplicates. I suppose I can define
the hash keys if they don't already exists and export the keys into an array
with the keys function. Is that what you are hinting towards?

Thanks,
Brian

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]
Sent: Friday, October 29, 2004 2:56 PM
To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
Subject: RE: easy way to add element to array


[EMAIL PROTECTED] wrote:
> Hi. I'm working with an array that i'm pushing values on to, but I
> don't want there to be any duplicates. Is there a perl function of an
> easy way to check if an array already contains a value before I push
> that value on to it?

First consider whether you should be using a hash.

If you still want to use an array, the Tie::File::Array module will do the
trick.

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




RE: each character in a string

2004-10-29 Thread Bob Showalter
[EMAIL PROTECTED] wrote:
> Hi All,
> I have to write a code wherein I have to access each character in a
> string and compare it with '-'
> 
> $_ = $seq1[0];
> while(/./g) {
>  if($1 eq '-') {
> $res1[0] .= '-';
>  }
>  else {
> $res1[0] = "A";

Do you mean .= here?

>  }
> }

Are you trying to change all the non-dash chars to "A"? Why not something
like:

$res1[0] = do { local $_ = $seq1[0]; s/[^-]/A/g; $_ };

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




RE: easy way to add element to array

2004-10-29 Thread Bob Showalter
[EMAIL PROTECTED] wrote:
> Though about using a hash but I don't have a need for a Key/Value
> combination. I just need a list without duplicates. I suppose I can
> define the hash keys if they don't already exists and export the keys
> into an array with the keys function. Is that what you are hinting
> towards? 

Yes, that's what I'm hinting at :~)

A hash would be called for if you need to do repeated tests to see whether
an element exists in the set. The downside to pulling the unique values with
keys() is that you lose the original order, if that matters.

Tie::Array::Unique will take care of the problem and preserve the order,
while letting you push entries onto the array without worrying about
creating duplicates.

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




Re: Newbie: Perl Vs Shell

2004-10-29 Thread Thomas Bätzler
"Chris Devers" <[EMAIL PROTECTED]> wrote:
On Fri, 29 Oct 2004, Thomas Bätzler wrote:
Chris Devers <[EMAIL PROTECTED]> claimed:
[...]
> well written shell scripts don't need Perl and well written Perl
> scripts don't need external shell commands.
I think that's the "ivory tower" point of view. Down here in the
trenches, it's more like "a well-written Perl script uses shell
commands where it makes sense". Obviously the art is in knowing where
it makes sense and where not.
[...]
Likewise, shell scripts with lines like this:
grep 'foo' logfile \
 | perl -pe '$l=$_; ($s=$l) =~ m/^([0-9])+/; print scalar localtime $s, " ";' \
 | sed -e 's#\( 200[0-9]\) 1[0-9]*#\1#' -e 's#\(.*\)#   \1#' \
 >> $htmllog
Are complex enough that it's probably worth considering rewriting the
whole thing in Perl. Perl is a much bigger program than most of the
standard shell tools, so a script like this is probably slower than it
needs to be.
One might argue that using sed as a filter for a Perl program is dubious -
after all, you already have the line you're interested in, so why not
do it all in Perl. On the other hand, it's probably a command line that
was plugged together on the fly, to do just one job.
In one point you're wrong, though - for selecting lines from a file and
mangling them into another format, a hybrid of shell grep and perl is
actually much faster than a pure Perl implementation - from personal
experience I'd say 1.5 to 2 times on a single CPU system. If you're on
a SMP box, probably even faster. This is no doubt because grep uses
a simpler pattern matching algorithm, and also because it's much more
efficient on I/O.
Moreover, to get this down to a reasonable line length, it
uses an obtuse style that would really be more readable as a Perl script
opaque? In any case, it looks like the person who wrote the code was
not very proficient in Perl. Otherwise (s)he's used something like
   perl -pe 's/^(\d+)/localtime $1/e'
to turn time_t timestamps to human-readable dates ;-)
spread out over several more lines. In the long run, the pure Perl
version would be easier to maintain, even if in the short term it seems
more expedient to kludge in a tricky bit in the shell script using a
single call to Perl, then reverting to shell tools afterwards.
Well, I wouldn't argue with the value of setting up proper scripts
that ones colleagues can use, too. Throw in a bit of Getopt::* and
things get downright luxurious ;-)  Still, it's not Perl for Perl's sake,
so if I can be more efficient by tying in other tools, I do that. And
obviously Perl was meant for stuff like that.
What's expedient isn't always a good idea in the long term.
Who could argue with that ;-)
Thomas 

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



Re: Newbie: Perl Vs Shell

2004-10-29 Thread daggerquill unknown
On Fri, 29 Oct 2004 13:36:00 -0400 (EDT), Chris Devers
<[EMAIL PROTECTED]> wrote:
> On Fri, 29 Oct 2004, Jenda Krynicky wrote:
> 
> > Actually no. They are generaly not very fast. The reason is that the
> > shell interpreter needs to create a new process for each and every 
> > commend you specify in the script [...]
> 
> Is this true even for built in shell commands? For example, commands
> like cd, echo, export, kill, test, etc are all built in to Bash -- does
> an external process run whenever you invoke one of these?
> 
> --
> Chris Devers
> 
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 

It depends on the complexity of the command, and the syntax it is
invoked with.  It's complicated, but in general "system" spawns a
subshell when called with a single argument, and does not call a
subshell when called with multiple arguments, unless the shell
function called is very simple, in which case even the single-argument
call is handled by perl.  It's important to remember also that the
arguments are the number of arguments you give to the "system"
function, not the arguments you supply for whatever shell command
you're calling.

so:
 system "ls /usr/bin"  # simple, no subshell
 system 'lsof -u $PID | grep perl'  # complicated, shell probably spawned
 system ("ls", "-l", $mydir) # multiple arguments,
subshell not spawned.

I hope this helps.

-jay savage

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




RE: how summarise results from 2 hashes?

2004-10-29 Thread Charles K. Clarkson
Maxipoint Rep Office <[EMAIL PROTECTED]> wrote:

: Charles K. Clarkson [mailto:[EMAIL PROTECTED] wrote:
:
: : Maxipoint Rep Office <[EMAIL PROTECTED]> top-posted:
: :
: : : Additional: $hasfromform1 have as result only 1 key
: : : $hasfromform2 can have multiple keys (ever key by
: : : $hasfromform2 must be +
: : : with other $hasfromform2 key)
: :
: : A hash contains keys and values. Are you trying to sum
: : all the keys or
: : all the values of $hasfromform2?
: :
: : Show us what is in each of the hashes you are using.
: :
: : $hasfromform1
: : $forma
: : $hasfromform2
:
: RE: inside are numbers!
: my $hasfromform1 =
:   $hasfromform1->{$forma->{hasfromform1valuefromform}};
:
: my $hasfromform2 =
:   $hasfromform2->{$forma->{hasfromform2valuefromform}};

Thanks, but that doesn't tell me what is in there. Show us
the actual values in all three hashes. You can get the values
using the Dumper() function from the Data::Dumper module.

use Data::Dumper 'Dumper';

print Dumper( $hasfromform1, $forma, $hasfromform2 );


: above send all numbers from form into my .pm

I have no idea what that means.


: : : and at the end go: one key from $hasfromform1 + every
: : : key of $hasfromform2
: :
: :To get the sum of every value and every key in a hash, use
: : this.
: :
: : use List::Util 'sum';
: :
: : my %hash;
: :
: : @hash{ 1 .. 4 } = 5 .. 9;
: :
: : printf "Keys:   %s\n", sum keys %hash;
: : printf "Values: %s\n", sum values %hash;
: :
: RE:
:
: in factforeach(keys %{$hasfromform1}){
: : if($forma->{$_} eq $_){
: : $hasfromform1 +=  $hasfromform2->{$_};
:
: work when $hasfromform2 has 1 key only.

Show us a working example. Something we can run from our
own computer.


: How List::Util include into it?

I don't understand your question.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328




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




RE: Append on top

2004-10-29 Thread Rajesh Dorairajan
Title: RE: Append on top





I looked at the archives and found a mail by NYMI Jose where the code was pretty neat. It was actually for inserting in the middle of the file. However, I could not get it to append on top. I am enclosing the mail containing his code as attachment if someone likes to comment.

Jenda, I like the approach proposed by you. But I've the same question Ajey asked (Why 8*1024)?


Rajesh


-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]] 
Sent: Friday, October 29, 2004 7:29 AM
To: [EMAIL PROTECTED]
Subject: RE: Append on top



From:       [EMAIL PROTECTED]
> This is the way I would do it, however my code has been subject to
> criticism more that once in the past :)
> 
> open (FILE, "
> @file = ;
> close (FILE);
> $new_data = "This is my new line that I am going to put at the top\n";
> unshift (@file, $new_data); open (FILE, ">myfile.dat") or die; print
> FILE @file; close (FILE);


:-)


This is definitely a workable solution, there are just a few things 
to keep in mind.


1)This would mean that the whole file is read into the memory.
2)This would force Perl to search for end-of-lines and create an 
array.
3) You open the file in text mode in both cases. This may change the 
type of newlines in the file!


So it's fine for small files, but not so great for bigger ones.


If you want something more efficient you might try something like 
this:


open NEWFILE, '>', 'myfile.dat.tmp' 
  or die "Can't create myfile.dat.tmp: $^E\n";
print NEWFILE "the new stuff to put on top\n";
...


open OLDFILE, '<', 'myfile.dat'
  or die "Can't open the original file myfile.dat: $^E\n";
binmode(OLDFILE);
binmode(NEWFILE);
my $buff;
print NEWFILE $buff 
    while (read OLDFILE, $buff, 8*1024);
close NEWFILE;
close OLDFILE;
rename 'myfile.dat.tmp' => 'myfile.dat';


Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
    -- Terry Pratchett in Sourcery



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



 


From: NYIMI Jose (BMB) [EMAIL PROTECTED]
Sent: Thursday, May 06, 2004 12:44 AM
To: [EMAIL PROTECTED]
Subject: RE: How do I append text to a text file - in the 3rd row ?

Does this helps ?

#!perl -w
use strict;

my $text="this is appended text";

while(){
print;
print "$text\n" if $. == 3;
}

__DATA__
line1
line2
line3
line4
Line5


OUTPUT:

line1
line2
line3
this is appended text
line4
Line5

José.


 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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




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


Re: each character in a string

2004-10-29 Thread Ajey Kulkarni
Also, "Mastering Regular EXpressions" - Orielly book gives real
nice insight about this.

I'm still learning PERL...Sigh!
~A



On Fri, 29 Oct 2004, Gunnar Hjalmarsson wrote:

> [EMAIL PROTECTED] wrote:
> > I have to write a code wherein I have to access each character in a
> > string and compare it with '-'
> >
> > $_ = $seq1[0];
> > while(/./g) {
> >  if($1 eq '-') {
> > $res1[0] .= '-';
> >  }
> >  else {
> > $res1[0] = "A";
> >  }
> > }
> >
> > I have initialised $_ with the string in which I have to search. Now I
> > know that the while loop will read each and every character in the
> > string. I just need to get that character read to make the comparison. I
> > know $1 doesnt work because it is not :) Where is the value returned or
> > how can I assign a variable the value of the condition in the while loop ?
>
> As Ajey showed, $1 does work provided that you use capturing
> parentheses, or you can use $& (but read the warning in "perldoc perlre"
> if you consider the latter).
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>


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




Re: Newbie: Perl Vs Shell

2004-10-29 Thread Lawrence Statton N1GAK/XE2

[EMAIL PROTECTED] (Chris Devers) writes:

> On Fri, 29 Oct 2004, Jenda Krynicky wrote:
> 
> > Actually no. They are generaly not very fast. The reason is that the 
> > shell interpreter needs to create a new process for each and every 
> > commend you specify in the script [...]
> 
> Is this true even for built in shell commands? For example, commands 
> like cd, echo, export, kill, test, etc are all built in to Bash -- does 
> an external process run whenever you invoke one of these? 

No, that's why they're called shell builtins.  That functionality was
so common, that it was added into popular shell programs precisely to
save the cost of an exec() call.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.

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




Interpreting Benchmark test

2004-10-29 Thread Owen
My first foray into Benchmark with the code below produced these results; 

The file is 22000 lines, and there are 2 matches in the file.

[EMAIL PROTECTED] PerlScripts]$ perl benchmark.pl

Regex with modifer
YES
YES
timethis 100:  5 wallclock secs ( 4.84 usr +  0.50 sys =  5.34 CPU) @ 187265.92/s 
(n=100)

Regex without  modifer
YES
YES
timethis 100:  7 wallclock secs ( 4.75 usr +  0.57 sys =  5.32 CPU) @ 187969.92/s 
(n=100)

It would seem to me that the /o modifier makes little difference, or is it that I am 
using the modifer incorrectly or even using Benchmark incorrectly?


TIA


Owen





#!/usr/bin/perl -w

   use Benchmark qw(:all) ;
   use strict;
   
   my $count = 100;
   my $name = "STILL";
   my $file = "test.data";
   my $line;
   open (FH,"$file") || die "Can't open $file $!\n";
   print "\nRegex with modifer\n";
   
   timethis ($count, 
sub{
while(){
chomp;$line=$_;
if ($line=~/$name/o){print "YES\n"}
}});
close FH;

   open (FH,"$file") || die "Can't open $file $!\n";
   print "\nRegex without  modifer\n";

timethis ($count, 
sub{
while(){
chomp;$line=$_;
if ($line=~/$name/){print "YES\n"}
}}); 

__END__

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




Re: each character in a string

2004-10-29 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
Hi All,
Hello,
I have to write a code wherein I have to access each character in a
string and compare it with '-'
$_ = $seq1[0];
while(/./g) {
 if($1 eq '-') {
$res1[0] .= '-';
   ^^
 }
 else {
$res1[0] = "A";
   ^
Is that supposed to be '.=' instead of '='?
 }
}
I have initialised $_ with the string in which I have to search.
No need to do that really.
Now I
know that the while loop will read each and every character in the
string.
I don't know that "read" is the right term, it will iterate over each 
*non-newline* character.

I just need to get that character read to make the comparison. I
know $1 doesnt work because it is not :)
It doesn't work because $1 is set by the first pair of parentheses in the 
regular expression but you aren't using parentheses to capture the character.

Where is the value returned or
how can I assign a variable the value of the condition in the while loop ?

According to your code this will work:
$res1[ 0 ] = join '', 'A', $seq1[ 0 ] =~ /(-+)$/;
But if you really meant to code "$res1[0] .= 'A';" instead of "$res1[0] = 
'A';" then this will work:

( $res1[ 0 ] = $seq1[ 0 ] ) =~ s/([^\n-])/A/g;

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: easy way to add element to array

2004-10-29 Thread Zeus Odin
Also look at
   perldoc -q duplicate
and
   Perl Cookbook 4.6. Extracting Unique Elements from a List

"Brian Barto" <[EMAIL PROTECTED]> wrote in message ...
> Though about using a hash but I don't have a need for a Key/Value
> combination. I just need a list without duplicates. I suppose I can define
> the hash keys if they don't already exists and export the keys into an
array
> with the keys function. Is that what you are hinting towards?



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




Re: regex matching in a nested loop

2004-10-29 Thread Zeus Odin
Jason,

You state your question, and practically give the answer in the solution.
:-)

You have a for loop inside a while loop. Both loops set $_. You state that
you can not properly do your match within the for loop because you need the
$_ value set by the while loop. Well ... why don't you just "save" the value
of $_ set by while?

See code below:

"Jason Wozniak" <[EMAIL PROTECTED]> wrote in message ...


> lies in the while loop of my search subroutine.  If I use a for loop to
> iterate over all the passwords for each line of the input file, $_ is
> overwritten with a numeric value before the matching can take place, so
> I can't match the line I'm reading in from the file.  If I get rid of
> the for loop and use a counter like $count to iterate through my array,



>   while () {

while ( defined(my $line=) ) {

> for (0..$#passwords) {
>   if (/$passwords[$_]/) {

if ($line =~ /$passwords[$_]/) {

> print "Match found!\n";
> print TMPFILE $file
>   or die "Could not write to file: $!\n";
> }
>   }
> }
> }



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




Re: Append on top

2004-10-29 Thread John W. Krahn
Jenda Krynicky wrote:
From:   [EMAIL PROTECTED]
This is the way I would do it, however my code has been subject to
criticism more that once in the past :)
open (FILE, ";
close (FILE);
$new_data = "This is my new line that I am going to put at the top\n";
unshift (@file, $new_data); open (FILE, ">myfile.dat") or die; print
FILE @file; close (FILE);
This is definitely a workable solution, there are just a few things 
to keep in mind.

1)This would mean that the whole file is read into the memory.
2)This would force Perl to search for end-of-lines and create an 
array.
3) You open the file in text mode in both cases. This may change the 
type of newlines in the file!

So it's fine for small files, but not so great for bigger ones.
If you want something more efficient you might try something like 
this:

open NEWFILE, '>', 'myfile.dat.tmp' 
  or die "Can't create myfile.dat.tmp: $^E\n";
print NEWFILE "the new stuff to put on top\n";

open OLDFILE, '<', 'myfile.dat'
  or die "Can't open the original file myfile.dat: $^E\n";
binmode(OLDFILE);
binmode(NEWFILE);
my $buff;
print NEWFILE $buff 
	while (read OLDFILE, $buff, 8*1024);
close NEWFILE;
close OLDFILE;
rename 'myfile.dat.tmp' => 'myfile.dat';
You *can* of course modify the file in-place (if the OS supports it.)
my $file = 'myfile.dat';
my $text = "the new stuff to put on top\n";
open my $IN, '+<', $file or die "Cannot open '$file' for input: $!";
binmode $IN;
open my $OUT, '+<', $file or die "Cannot open '$file' for output: $!";
binmode $OUT;
$/ = \length $text;
while ( my $buff = <$IN> ) {
print $OUT $text;
$text = $buff;
print $OUT $text if eof $IN;
}

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Extracting Directories and Sub Directories and Counting

2004-10-29 Thread Ron Smith
Well I've moved this along a little further, but it
looks like I'm stuck on one last thing.

I'm getting;

C:\Perl\scripts\dir\dir\dir

  basename  0001
  basename  0002
  basename  0003
  basename  0004
  basename  0005
  basename  0006
  basename  0007
  basename  0008
  basename  0009
  basename  0010
  another_basename  0001
  another_basename  0002
  another_basename  0003
  another_basename  0004
  another_basename  0005
  another_basename  0006
yet_another_name  0001
yet_another_name  0002
yet_another_name  0003
yet_another_name  0004
yet_another_name  0005

C:\Perl\scripts\dir\dir\dir\sub_directory

  basename  0001
  basename  0002
  basename  0003
  basename  0004
  basename  0005
  basename  0006
  basename  0007
  basename  0008
  basename  0009
  basename  0010

C:\Perl\scripts\dir\dir\dir\sub_directory\deeper_sub

basename  0001
basename  0002
basename  0003
basename  0004

The following is the re-worked script:

snip-

#!/usr/bin/perl -w

use strict;

my %HoA;
for ( `dir /b/s` ) {
push @{ $HoA{$1} }, $2 if
/(.+)\\(\w+)\.(\d+)\.(\w+)$/;
}

my %count;
for my $dir ( sort keys %HoA ) {
print "$dir\n";
my @basenames = @{ $HoA{$dir} };
for my $frames ( @basenames ) {
$count{$frames} += 1;
printf "%30s\t%04d\n", $frames,
$count{$frames};
}
}

snip-

I'm trying to get the following output:

C:\Perl\scripts\dir\dir\dir

 basename  0010
 another_basename  0006
 yet_another_basename  0005

C:\Perl\scripts\dir\dir\dir\sub_directory

  basename  0010

C:\Perl\scripts\dir\dir\dir\sub_directory\deeper_sub

basename  0004

I've gone through 'perldoc perlreftut', but can't see
the last step.
--- Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote:

> [ replying to the list since that's where the
> discussion belongs ]
> 
> Ron Smith wrote (to me privately):
> > Thank you *very* much for furthering my 'Perl'
> knowlege. I've
> > never see a variable like '@{ $HoA{$dir} }'
> before.
> 
> Well, it's not a special variable type. $HoA{$dir}
> is a reference to an 
> anonymous array, which you dereference with the @{
> $HoA{$dir} } construct.
> 
> > I'm just at the 'Llama' level. I think I
> understand what's going
> > on though.
> > Your solution:...
> > 
> > my %HoA;
> > for ( `dir /b/s` ) {
> >push @{ $HoA{$1} }, $2 if
> /(.+)\\(\w+)\.\d+\.\w+$/;
> > }
> > 
> > for my $dir (sort keys %HoA ) {
> >print "$dir\n", join( "\n", @{ $HoA{$dir} }
> ), "\n\n";
> > }
> > 
> > ...worked out fine. This one took some thought for
> me to wrap my
> > head around. Thank you so *very* much for showing
> me something
> > new and very useful.
> 
> I now realize that the small piece of code above
> combines three 
> components of Perl that make it a really powerful
> programming language: 
> Hashes, references and regular expressions.
> 
> > I'm attempting to play around with this new tool
> to get it to do
> > different things, but I'm running into another
> problem. I can't
> > seem to pull the elements back out from the arrays
> properly. I'm
> > tring to count the basenames now. I get what looks
> like memory
> > addresses instead. I think these are the
> references to the actual
> > arrays that you were eluding to.
> 
> Sounds plausible. :)
> 
> > I was using parts of the script you helped me out
> on before to do
> > the counting of the basenames:
> > 
> > #!/usr/bin/perl -w
> > 
> > use strict;
> > 
> > my @paths = `dir /b`;
> > my @basenames = &extract_names(@paths);
> > 
> > sub extract_names {
> >my ($name, @names);
> >for (@_) {
> >if (/(\w+)\.\d+\.\w+$/) {
> >$name = $1;
> >$name =~ s/$/\n/;
> 
> Hmm.. It's usually practical to not add "\n" like
> that, but take care of 
> linebreaks in connection with printing the variable.
> Without adding 
> "\n", instead of saying
> 
>  print @basenames;
> 
> you can say e.g.
> 
>  print join("\n", @basenames), "\n";
> 
> >push @names, $name;
> >}
> >}
> >@names;
> > }
> > 
> > my (%count, $frames);
> > for $frames (@basenames) {
> >chomp ($frames);
> >$count{$frames} += 1;
> > }
> > for $frames (sort keys %count) {
> ># print "$frames\t1-$count{$frames}\n";
> >printf "%20s\t%04

Re: Printing to a file

2004-10-29 Thread Zeus Odin
my $hero = 'John Krahn';
$hero =~ s/John Krahn/Jenda Krynicky/;

>:-)

I can't believe I wrote what I thought was a thoughtful post that would
hopefully make perl.beginners a better place to frequent (good luck!) and
all I get is:

Dude, Randal is spelled with one L not two. Pay attention. I'm John Krahn.

Obviously, I'm kidding. I honestly did know that Randal was spelled with one
L but while typing, sometimes I can't see the forest for the trees.
Hopefully, next time I have tunnel vision, I will remember.

Keep the thoughtful and informative posts coming.
-ZO

"John W. Krahn" <[EMAIL PROTECTED]> wrote in message ...

> > Charles Clarkson, Randall Schwartz, and John Krahn (I'm only naming
three.
>
> You probably meant Randal Schwartz (one "l".)   :-)



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




Re: Extracting Directories and Sub Directories and Counting

2004-10-29 Thread Gunnar Hjalmarsson
Ron Smith wrote:
The following is the re-worked script:
snip-
#!/usr/bin/perl -w
use strict;
my %HoA;
for ( `dir /b/s` ) {
push @{ $HoA{$1} }, $2 if
/(.+)\\(\w+)\.(\d+)\.(\w+)$/;
}
The two last pairs of parentheses are redundant.
my %count;
for my $dir ( sort keys %HoA ) {
print "$dir\n";
my @basenames = @{ $HoA{$dir} };
for my $frames ( @basenames ) {
$count{$frames} += 1;
printf "%30s\t%04d\n", $frames,
$count{$frames};
}
}
Instead of that, you probably want:
for my $dir ( sort keys %HoA ) {
print "$dir\n";
my @basenames = @{ $HoA{$dir} };
my %count;
for my $frames ( @basenames ) {
$count{$frames} += 1;
}
for ( sort keys %count ) {
printf "%30s\t%04d\n", $_, $count{$_};
}
}
I made two changes:
- The %count hash is now declared within the outer loop, since I suppose 
you want to have it cleared before the program starts iterating over the 
basenames of a new directory.
- The printf() statement has been moved to a separate inner loop. The 
logic bids that %count is printed only after it has been populated.

HTH
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Newbie: Perl Vs Shell

2004-10-29 Thread Chris Devers
On Fri, 29 Oct 2004, Lawrence Statton N1GAK/XE2 wrote:

> [EMAIL PROTECTED] (Chris Devers) writes:
> 
> > On Fri, 29 Oct 2004, Jenda Krynicky wrote:
> > 
> > > Actually no. They are generaly not very fast. The reason is that 
> > > the shell interpreter needs to create a new process for each and 
> > > every commend you specify in the script [...]
> > 
> > Is this true even for built in shell commands? For example, commands 
> > like cd, echo, export, kill, test, etc are all built in to Bash -- 
> > does an external process run whenever you invoke one of these?
> 
> No, that's why they're called shell builtins.  That functionality was 
> so common, that it was added into popular shell programs precisely to 
> save the cost of an exec() call.
 
Okay, that's what I thought, but Jenda was pretty unambiguous there, and 
I've certainly been wrong about past assumptions...

 

-- 
Chris Devers

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




Re: Extracting Directories and Sub Directories and Counting

2004-10-29 Thread Gunnar Hjalmarsson
Gunnar Hjalmarsson wrote:
for my $dir ( sort keys %HoA ) {
print "$dir\n";
my @basenames = @{ $HoA{$dir} };
my %count;
for my $frames ( @basenames ) {
$count{$frames} += 1;
}
for ( sort keys %count ) {
printf "%30s\t%04d\n", $_, $count{$_};
}
}
Or with less typing:
for ( sort keys %HoA ) {
print "$_\n";
my %bn;
%bn = map { $_, ++$bn{$_} } @{ $HoA{$_} };
printf "%30s\t%04d\n", $_, $bn{$_} for sort keys %bn;
}
;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: easy way to add element to array

2004-10-29 Thread Jeff 'japhy' Pinyan
On Oct 29, Bob Showalter said:

>[EMAIL PROTECTED] wrote:
>> Though about using a hash but I don't have a need for a Key/Value
>> combination. I just need a list without duplicates. I suppose I can
>> define the hash keys if they don't already exists and export the keys
>> into an array with the keys function. Is that what you are hinting
>> towards?
>
>Yes, that's what I'm hinting at :~)
>
>A hash would be called for if you need to do repeated tests to see whether
>an element exists in the set. The downside to pulling the unique values with
>keys() is that you lose the original order, if that matters.
>
>Tie::Array::Unique will take care of the problem and preserve the order,
>while letting you push entries onto the array without worrying about
>creating duplicates.

Thank you for the plug. :)

Tie::Array::Unique is a transparent solution -- that is, all you do is
tie the array to T::A::U and things get done.  Using hashes isn't all that
hard, but T::A::U does that for you.

-- 
Jeff "japhy" Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart


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