RE: why $000 is a valid variable name?

2004-11-18 Thread Jose Alves de Castro
On Thu, 2004-11-18 at 14:27, Larsen, Errin M HMMA/IT wrote:
   BUT ... When I removed the warnings and strict, and stopped using
 my, it works:

replacing my with our does the trick too.


-- 
José Alves de Castro [EMAIL PROTECTED]
  http://jose-castro.org/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: why to use 1)use CGI,2)use Strict ,3)use Carp in script

2004-11-04 Thread Jose Alves de Castro
On Thu, 2004-11-04 at 09:31, supriya devburman wrote:
 hi

Hi

 why we r using
 1)use CGI,

We only use CGI when we want to use methods from that module (usually on
web pages); see `perldoc CGI` for more information on what you can do
with it.

 2)use Strict,

The correct name is strict. This is a pragma. We use it because it's a
good method to use strict (and also warnings).

strict forces some strictures (see `perldoc strict` for more
information) that make your code harder to be broken.

 3)use Carp 
 in the begining of script sometimes. What is the use
 of it.Is the files CGI.pm,Strict.pm,Carp.pm default
 with PERL.

If you're asking if those modules come with Perl itself, I believe the
answer to be yes.

 Thnx

I hope that was helpful O:-)

jac

 __
 Do You Yahoo!?
 Tired of spam?  Yahoo! Mail has the best spam protection around 
 http://mail.yahoo.com
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Accessing 2D array

2004-10-28 Thread Jose Alves de Castro
On Thu, 2004-10-28 at 10:19, Khairul Azmi wrote:
 I've been trying to solve this problem using many techniques I found
 on the websites but still unsuccessfully

Hi.

I don't have much time, so I probably won't be able to explain this
right now, but here's a working version of your code, give it a look:

#!/usr/bin/perl -w
use strict;

sub func {
my @local_array = @_;
for my $i ( 0 .. @local_array - 1 ) {
for my $j ( 0 .. @{$local_array[$i]} - 1 ) {
print $local_array[$i][$j] ;
}
print \n;
}

}

my @myarray = ( [1, 2, 3, 4, 5], [6, 7, 8, 9, 10] );

func(@myarray);


Regards, and HTH,

jac

 sub func {
   my (@local_array) = @_;
 
for (my $i=0;$i@local_array;$i++) {
   for (my $j=0;$j@local_array[$i];$j++) {
   print $local_array[$i[[$j] ;
}
 print \n;
 }
 
 $myarray[0]=(1,2,3,4,5);
 $myarray[1]=(6,7,8,9,10);
 
 func (@myarray);
 
 Thanks in advance
 
 Azmi
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: $_. and $_,

2004-10-13 Thread Jose Alves de Castro
On Wed, 2004-10-13 at 10:48, E.Horn wrote:
 Hallo!

Hi.

 Stupid question, but i am a perlbeginner! :-(
 What is the difference between $_. and $_, ??

$_ is a variable (the context variable)
A single dot is the concatenation operator
A single comma is the list separator

So:

$_. isn't really something, but two different things: a variable and
 an operator... and that will only be valid if something else would
 follow (so that the operator could have something to work on). Example:

$_ . \n

That would result in the concatenation of $_ with a string containing
 the new line character, \n.

$_, would be valid code, but it would probably serve no other purpose
 than the one of $_ by itself.

Was that helpful?

If not, give an example and we'll try to put some light on it :-)

 Regards

Best regards,

jac

-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: OT: Email syntax validation

2004-10-05 Thread Jose Alves de Castro
On Mon, 2004-10-04 at 17:57, JupiterHost.Net wrote:
  
  When people undiscriminatingly advocate the use of modules whenever
  possible, I get unhappy. I'm using modules when I consider it to be
  suitable.
  
 
 Peace my friend, do whatever you want.
 It wasn't an attack, that's what the smiley's are for :)

That's why I try to use smileys all the time... so people know I'm in a
 friendly mood :-)

 Chill chill chill ;p
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need help with script

2004-09-30 Thread Jose Alves de Castro
On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote:
  I would like the output in the following format
  object1...tabDescription1
  object2...tabDescription2
  object3...tabDescription3
 
 
  perl -lne 'BEGIN{$/=\n\n;}s/\n/\t/;print' FILENAME
  
  
  
  perl -l -00pe's/\n/\t/' FILENAME
 
 That's pretty slick you guys, he's sure to get an A+ ;)
 
 If your teacher requires the quotes to be removed:

What if the teacher requires an explanation? O:-)

It is my opinion that code should be explained, at least in this list.
 You're trying to teach people how to fish (and maybe swim). Giving them
 fish is good, of course, but tell them how you got it :-)

That said, nice code :-)

   perl -l -00pe's/\n/\t/;s/\//g;' FILENAME
 
 :)
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How Can I rename File using Perl?..

2004-09-30 Thread Jose Alves de Castro
On Thu, 2004-09-30 at 10:20, Roime bin Puniran wrote:
 How can i rename any file using PERL?...Where should i start?..Where i can find any 
 tutorial?

Try this

perldoc -f rename

HTH, :-)

jac

 This e-mail and any attachments may contain confidential and
 privileged information. If you are not the intended recipient,
 please notify the sender immediately by return e-mail, delete this
 e-mail and destroy any copies. Any dissemination or use of this
 information by a person other than the intended recipient is
 unauthorized and may be illegal.
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how do i describe a perl user?

2004-09-30 Thread Jose Alves de Castro
On Thu, 2004-09-30 at 17:07, Sano Babu wrote:
 just wondering what a user of Perl may be called?

I would call him a very intelligent person O:-)

 Perler?? Theres
 got to be some fancy name for it. Perl is not just another programming
 language.. I reckon its much more like a religion with attitude.. :)

OK, a bit more seriously, now: Perl hacker and Perl monger are
 frequently used...

Would anyone more experienced than me care to send his two cents on this
 one? :-)

 Cheers,
 SanoBabu
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to access first key of Hash of Hash

2004-09-29 Thread Jose Alves de Castro
On Wed, 2004-09-29 at 14:37, Edward Wijaya wrote:
 Hi,

Hi.

 I have this HoH:
 my %HoH = (
 firstkey = { A = 'blabla',
   B = 'dadada',
   C = 'tititi',}
 );
 
 generated with
 
 $HoH{$fkey}{$alpha}=$text;
 
 how can I access the value
 of the first key, so that it gives: firstkey

If I understood this correctly, you want to do this:

print $fkey;

HTH, :-)

jac

 I tried this with no avail:
 
 print $HoH{$fkey}\n
 
 
 
 Regards,
 Edward WIJAYA
 SINGAPORE
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to access first key of Hash of Hash

2004-09-29 Thread Jose Alves de Castro
On Wed, 2004-09-29 at 15:18, Edward Wijaya wrote:
 On 29 Sep 2004 14:58:00 +0100, Jose Alves de Castro  
 [EMAIL PROTECTED] wrote:
  If I understood this correctly, you want to do this:
 
 
 So sorry for being not clear.
 I will extend just a bit.
 
 Suppose I have:
 
 my %HoH = (
 firstkey = { A = 'blabla',
   B = 'dadada',
   C = 'tititi',}
 secondkey = { D = 'blabla',
E = 'dadada',
F = 'tititi',}
 
 );
 
 and I generated that HoH with this:
 
 $HoH{$fkey}{$alpha}=$text;
 
 namely:
 
 firstkey, secondkey from $fkey
 A, B, C, etcfrom $alpha
 blabla etc  from $text
 
 my question is how can I print output like:
 
 firstkey
 secondkey

for (keys %HoH) {
  print $_\n;
}

Was that it?

 given the construction variables as mention before.
 
 Thanks
 
 Regards,
 Edward WIJAYA
 SINGAPORE
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to access first key of Hash of Hash

2004-09-29 Thread Jose Alves de Castro
On Wed, 2004-09-29 at 15:32, Edward Wijaya wrote:
 On 29 Sep 2004 15:20:39 +0100, Jose Alves de Castro  
 [EMAIL PROTECTED] wrote:
 
 
 
  for (keys %HoH) {
print $_\n;
  }
 
 
 It seems so. Thanks a lot.

Glad to be of help :-)

 I thought 'keys' are only for simple hash.

 Regards,
 Edward WIJAYA
 SINGAPORE
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Inline Edit -- File name

2004-09-22 Thread Jose Alves de Castro
On Wed, 2004-09-22 at 15:24, [EMAIL PROTECTED] wrote:
 How will I get the file name when I do an inline edit like this:
 
 perl -i.orig -pe '$_ = filename $_' filename

That won't compile, but I believe you're posting something like a proof
of concept rather then code...

If I get this correctly, you're looking for the $ARGV variable. Check
out:

perldoc perlvar

 How would I get the file name in filename?
 
 Thanks,
 Rex
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: HINT: regex coach

2004-09-08 Thread Jose Alves de Castro
On Wed, 2004-09-08 at 10:17, Ing. Branislav Gerzo wrote:
 Hi,
 
 many of us need sometime fast help with regex. I recently found on the
 web really nice and easy program. Maybe someone of you already know
 it, for those, who don't it is REGEX COACH, download it from:
 
 http://www.weitz.de/regex-coach/

Just so this message isn't left unanswered, I'll state:

Yes, it seems to be a very nice program, and it would probably help lots
of beginners (and not only).

There, I said it :-)

jac

 Notes:
 The Regex Coach is a graphical application for Linux and Windows which
 can be used to experiment with (Perl-compatible) regular expressions
 interactively. It has the following features:
 
 It shows whether a regular expression matches a particular target
 string.
 
 It can also show which parts of the target string correspond to
 captured register groups or to arbitrary parts of the regular
 expression.
 
 It can walk through the target string one match at a time. 
 
 It can simulate Perl's split and s/// (substitution) operators. 
 
 It tries to describe the regular expression in plain English. 
 
 It can show a graphical representation of the regular expression's
 parse tree.
 
 It can single-step through the matching process as performed by the
 regex engine.
 
 Everything happens in real time, i.e. as soon as you make a change
 somewhere in the application all other parts are instantly updated.
 
 
 -=x=-
 Skontrolované antivírovým programom NOD32
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: Reading Multiple Lines

2004-09-08 Thread Jose Alves de Castro
On Wed, 2004-09-08 at 18:01, Eduardo Vázquez Rodríguez wrote:
 Hello
 
 I am writing scripts that  process big files which contains too many 
 lines (aproximately 700 000 lines per file). My strategy until now to 
 solve this problem is reading line per line, something like this
 
 while (FILE)
 {
 dosomethingwith($_);
 }
 
 Is there any way of working with multiple lines at the same time? can 
 anyone suggest any better strategy?

From a discussion on the Fun-With-Perl mailing list:

while (my @a = map { eof() ? () : scalar  } 1 .. $n) {
dosomethingwith(@a); # @a contains $n lines
}

HTH,

jac

 -- 
 Eduardo Vázquez Rodríguez [EMAIL PROTECTED]
 Consultoría Implantación
 Tel. 5322 5200
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: Foo (Bar)---I now see the light! (Or that which is made light of)

2004-09-08 Thread Jose Alves de Castro
From dictionary.com :


jargon Another common metasyntactic variable; see foo.
Hackers do *not* generally use this to mean FUBAR in either
the slang or jargon sense.

According to a german correspondent, the term was coined
during WW2 by allied troops who could not pronounce the german
word furchtbar (horrible, terrible, awful).



Interesting :-) Because whenever I write foobar, I don't mean
horrible, terrible nor awful :-)


On Wed, 2004-09-08 at 18:13, jason corbett wrote:
   
  
 
 
 jason corbett [EMAIL PROTECTED] wrote:
 As a newbie, I have seen the statement foo (bar) mentioned in books and and even 
 on this site. I haven't yet seen what this actually mean as I can assume that its 
 just for examples. If I am wrong please explain in detail what this is about.
 
 Thanks,
 JC
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: HINT: regex coach

2004-09-08 Thread Jose Alves de Castro
On Wed, 2004-09-08 at 10:17, Ing. Branislav Gerzo wrote:
 Hi,
 
 many of us need sometime fast help with regex. I recently found on the
 web really nice and easy program. Maybe someone of you already know
 it, for those, who don't it is REGEX COACH, download it from:
 
 http://www.weitz.de/regex-coach/

Just so this message isn't left unanswered, I'll state:

Yes, it seems to be a very nice program, and it would probably help lots
of beginners (and not only).

There, I said it :-)

jac

 Notes:
 The Regex Coach is a graphical application for Linux and Windows which
 can be used to experiment with (Perl-compatible) regular expressions
 interactively. It has the following features:
 
 It shows whether a regular expression matches a particular target
 string.
 
 It can also show which parts of the target string correspond to
 captured register groups or to arbitrary parts of the regular
 expression.
 
 It can walk through the target string one match at a time. 
 
 It can simulate Perl's split and s/// (substitution) operators. 
 
 It tries to describe the regular expression in plain English. 
 
 It can show a graphical representation of the regular expression's
 parse tree.
 
 It can single-step through the matching process as performed by the
 regex engine.
 
 Everything happens in real time, i.e. as soon as you make a change
 somewhere in the application all other parts are instantly updated.
 
 
 -=x=-
 Skontrolované antivírovým programom NOD32
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: PERL and Mobile Devices.

2004-08-24 Thread Jose Alves de Castro
I know this is old stuff, but it might be interesting to some of you

On Fri, 2004-08-13 at 14:33, James Edward Gray II wrote:
 On Aug 10, 2004, at 3:35 PM, JupiterHost.Net wrote:
 
  I remember hearing some cell phones had perl and maybe PDA's???
 
 Really?  I would be very interested to know what cell phone that is...

The Nokia 6600, apparently

http://www.mobilewhack.com/programming/perl/perl_on_nokia_at_foo.html


 Perl has a pretty big overhead compared to what mobile devices offer.  
 I've seen ports for Windows CE and the Sharp Zaurus, but I wasn't aware 
 of any others.
 
 James
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: pulling out a,an, the from beginning of strings

2004-08-24 Thread Jose Alves de Castro
On Tue, 2004-08-24 at 15:04, Tim McGeary wrote:
 I need to pull out articles a, an, and the from the beginning of 
 title strings so that they sort properly in MySQL.  What is the best way 
 to accomplish that if I have a single $scalar with the whole title in it?

I would go with substitutions:

$scalar =~ s/^(?:a|an|the)//i;

 Thanks,
 Tim
 
 -- 
 Tim McGeary
 [EMAIL PROTECTED]
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: pulling out a,an, the from beginning of strings

2004-08-24 Thread Jose Alves de Castro
On Tue, 2004-08-24 at 15:04, Tim McGeary wrote:
 I need to pull out articles a, an, and the from the beginning of 
 title strings so that they sort properly in MySQL.  What is the best way 
 to accomplish that if I have a single $scalar with the whole title in it?

I would go with substitutions:

$scalar =~ s/^(?:a|an|the)//i;

 Thanks,
 Tim
 
 -- 
 Tim McGeary
 [EMAIL PROTECTED]
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: Between times

2004-08-24 Thread Jose Alves de Castro
On Tue, 2004-08-24 at 14:49, rmck wrote:
 Hello,

Hi

 I have a script that I want to print only if between 08:00 and 17:00. Would I match 
 every hour then print?? Any cleaner way to do this would be great. Thanks
 
 my($sec,$min,$hour,$mday,$mon);
 ($sec,$min,$hour,$mday,$mon)=localtime;

I would change this to

my ($sec,$min,$hour,$mday,$mon) = localtime;

 $timestamp=sprintf(%3s %02d %02d:%02d:%02d,$Month[$mon],$mday,$hour,$min,$sec);
  
 my $pidstring=pid(.$$.),;
  
 while(STDIN){
   $line = $_;
   if($line=~/OK/){
 open( OKLIST,/var/log/log.ok);
 print OKLIST $timestamp,:,$pidstring,$line;
 close(OKLIST);
   }else{
 
 if ( $hour =~ /^(08:|09:|10:|11:|12:|13:|14:|15:|16:|17:)/){

if ($hour  7 and $hour  18){

that would do the trick

 open( ERRLIST,/var/log/err.ok);
 print ERRLIST $timestamp,:,$pidstring,$line;
 close(ERRLIST);
 chomp($line);
  }
   }
 }
 exit;
 
 
 
 rob
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: pulling out a,an, the from beginning of strings

2004-08-24 Thread Jose Alves de Castro
On Tue, 2004-08-24 at 15:16, Tim McGeary wrote:
 Jose Alves de Castro wrote:
  On Tue, 2004-08-24 at 15:04, Tim McGeary wrote:
  
 I need to pull out articles a, an, and the from the beginning of 
 title strings so that they sort properly in MySQL.  What is the best way 
 to accomplish that if I have a single $scalar with the whole title in it?
  
  
  I would go with substitutions:
  
  $scalar =~ s/^(?:a|an|the)//i;
 
 So that I am understanding this process, what does each part mean?  I 
 assume that the ^ means beginning of the variable... is that correct? 
 What about (?: ?

The ^ means the beginning of the string in $scalar, indeed.

As for the rest, I decided to group a, an and the with brackets,
or otherwise the regex would have been /^a|^an|^the/

Regarding the :? , that's just so variable $1 doesn't end up with
whatever was removed, as there was no need for that.

Search for Non-capturing groupings under perldoc perlretut, if you
need more information

 tyia,
 Tim

HTH, :-)

jac

-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: security on a html page with perl.

2004-08-24 Thread Jose Alves de Castro
On Tue, 2004-08-24 at 15:22, Chris Devers wrote:
 On Tue, 24 Aug 2004, Joe Echavarria wrote:
 
   After a user fill out a form and submit it a perl
  script takes the user to a download page of my
  website.  how can i prevent a user from directly
  access the download page using the web browser.., for
  example http://www.mydomain.com/download_page.html, i
  only want the user to able to download the file if
  he/she fill out and submit the form.
 
   Any help on how to do that ?
 
 Users can *always* get around such barriers, so don't get your hopes up 
 that it will be perfect.
 
 That said, you can make it harder, but not impossible, to get to the 
 download page without filling out the form first.
 
 The obvious way I can think of to do this is to make the download page a 
 script that checks to see that:
 
* mandatory form fields are defined as input for the download script
* the referring page is your original form (this one is probably less
  important than the previous criteria, if you think about it)
 
 If these are not verified, send the user back to the form with a note 
 saying that fields X, Y, and Z still need to be filled out.

This gave me an idea... one could have a hidden field in that form :-)

This way, you could know if the user came from a form with that field or
not (note: if the user came from a form with that field, not if the
user came from that form). Then you can point him to the right address
:-)

 If these are verified -- or, more to the point, if the form fields you 
 need are verified -- then that's about as good as forcing the user to 
 have visited the first page to begin with.
 
 
 -- 
 Chris Devers
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: pulling out a,an, the from beginning of strings

2004-08-24 Thread Jose Alves de Castro
On Tue, 2004-08-24 at 15:39, Chris Devers wrote:
 On Tue, 24 Aug 2004, Jose Alves de Castro wrote:
 
  On Tue, 2004-08-24 at 15:04, Tim McGeary wrote:
  I need to pull out articles a, an, and the from the beginning of
  title strings so that they sort properly in MySQL.  What is the best way
  to accomplish that if I have a single $scalar with the whole title in it?
 
  I would go with substitutions:
 
  $scalar =~ s/^(?:a|an|the)//i;
 
 Why not save the data for later by moving the article to the end?
 
  $scalar =~ s/^(?:a|an|the)\s+(.*)/$2, $1/i;
 
 That way, A Tale of Two Cities should become Tale of Two Cities, A, 
 and if you have to reconstitute the original title later, you haven't 
 thrown anything away...

I second this :-)

 -- 
 Chris Devers
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: security on a html page with perl.

2004-08-24 Thread Jose Alves de Castro
On Tue, 2004-08-24 at 15:36, Chris Devers wrote:
 On Tue, 24 Aug 2004, Jose Alves de Castro wrote:
 
  On Tue, 2004-08-24 at 15:22, Chris Devers wrote:
 
  The obvious way I can think of to do this is to make the download page a
  script that checks to see that:
 
 * mandatory form fields are defined as input for the download script
 * the referring page is your original form (this one is probably less
   important than the previous criteria, if you think about it)
 
  If these are not verified, send the user back to the form with a note
  saying that fields X, Y, and Z still need to be filled out.
 
  This gave me an idea... one could have a hidden field in that form :-)
 
 But this doesn't really change much: anyone trying to get around the 
 entry form, for whatever reason, isn't going to have to work very hard 
 to have the insight that they should look at the html source to see if 
 there are any hidden fields.

No, it doesn't change much. I guess I misread the original email. I was
thinking that, this way, sending a mail with a link directly to the
script wouldn't be enough to download the file. The user had to start
from some page. But thinking better about it, you're right, there's no
need for a hidden field, as there are already other fields that can be
validated...


One thing that could be done was to have the page with the form generate
the hidden field in a way that only the script could validate it...


-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


RE: pulling out a,an, the from beginning of strings

2004-08-24 Thread Jose Alves de Castro
On Tue, 2004-08-24 at 16:19, Bob Showalter wrote:
 Jose Alves de Castro wrote:
  On Tue, 2004-08-24 at 15:04, Tim McGeary wrote:
   I need to pull out articles a, an, and the from the beginning
   of title strings so that they sort properly in MySQL.  What is the
   best way to accomplish that if I have a single $scalar with the
   whole title in it? 
  
  I would go with substitutions:
  
  $scalar =~ s/^(?:a|an|the)//i;
 
 Two problems:
 
 1. This doesn't remove just the whole words; it removes parts of words as
 well. i.e. Analyzing Widgets would become alyzing Widgets
 
 2. It doesn't remove whitespace after the word, so The Widget Primer
 becomes  Widget Primer, which won't sort with the w's, due to the leading
 blank.
 
 Perhaps:
 
$scalar =~ s/^(a|an|the)\s*\b//i;
 
 would work better.

You're absolutely right. I think this is a sign that I need to go out,
eat and drink something, breath some fresh air, etc.

-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: a bug of -f option?

2004-08-17 Thread Jose Alves de Castro
On Tue, 2004-08-17 at 10:18, Gunnar Hjalmarsson wrote:
 Shu Hung wrote:
  I recently wrote a script with a '-f' file test inside.
  
  Normally, a '-f filename' returns TRUE if a file with that
  filename exist. My script returns TRUE for all the files -- except
  the largest one (9.7 GB) on my list (others are XX MB - XXX MB in
  size). Whenever I test it with '-f' test, it returns FALSE.
 
 Please show us code! Post a short but complete program that
 illustrates your claimed observation.
 
  Is this a bug of perl? Or am I mistaken?
 
 You are most likely mistaken. ;-)

I wouldn't be so sure... I had trouble in the past with several
utilities and large files... The new (don't know how new) Linux command
`tree` can't seem to find files with 2G, for instance...

It is also possible, though, that the problem is not with Perl itself...
what does Perl make use of to test if a file exists?

I think it wouldn't hurt to make some tests... but I also think I don't
have the necessary disk space for that... O:-)

Volunteers? :-)

jac

 -- 
 Gunnar Hjalmarsson
 Email: http://www.gunnar.cc/cgi-bin/contact.pl
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: set operations on arrays

2004-08-13 Thread Jose Alves de Castro
On Wed, 2004-08-11 at 18:13, Christopher J. Bottaro wrote:
 is it possible to do set opperations on arrays?  any cpan module or
 anything?  i want to do something like the following:

Yes, it is possible.

http://search.cpan.org/~muenalan/Class-Maker-0.05.18/Maker/Examples/Array.pm

or, if you're into OOP,

http://search.cpan.org/~muenalan/Class-Maker-Examples-0.01_02/Examples/Array.pm

 @intersection = set_intersection(@ar1, @ar2, @ar3);
 @ar1 = set_difference(@ar1, @intersection);
 @ar2 = set_difference(@ar2, @intersection);
 @ar3 = set_difference(@ar3, @intersection);
 
 thanks for the help.

HTH

jac

-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: awk like question

2004-08-13 Thread Jose Alves de Castro
On Fri, 2004-08-13 at 16:51, Errin Larsen wrote:
 um, can anyone explain the 'print' function below to me?
 
 specifically ... this:
 
   'print @F[0,5]'

The -a signal splits the input lines and stores the resulting elements
in @F

Example:

perl -nae 'print $F[1]\n' file.txt

where file.txt contains

one two three
four five six

prints:

two
five

Also, although this splitting on spaces, you can also use the -F signal
to define what you're splitting in.

See `perldoc perlrun`

HTH,

jac

PS:

Oh, print @F[0,5], of course, prints the first six elements of @F, and
since they're between double quotes, they're joined with whatever is in
$ (usually a space)

 How do I use this idea in a script instead of a command line?  also,
 how is the input getting into this function?  I mean, I understand $_
 and all, but on a command line, are we piping to that command?  what's
 with the '@F'?
 
 Thanks for the help!
 
 --Errin
 
 
 On Fri, 13 Aug 2004 09:52:04 -0400, [EMAIL PROTECTED]
 [EMAIL PROTECTED] wrote:
  Thanks too all who passed some knowledge on, but I ended up using :
  
   while (D) {
  
  ## look for 9840S and ebexpire
  ## declare OFS = tab
  ## tell split to split on IRS 0,15. very similar to awk
  print $
  
  if (($_ =~ /9840S/)  ($_ =~ /ebexpire, ebexpire/ )) {
   local $, = \t;
  print FOO +(split)[0,1,5], $/;
  #print +(split)[0,1,5], $/;
  
  Derek B. Smith
  OhioHealth IT
  UNIX / TSM / EDM Teams
  614-566-4145
  
  John W. Krahn [EMAIL PROTECTED]
  08/13/2004 08:51 AM
  
  To: Perl Beginners [EMAIL PROTECTED]
  cc:
  Subject:Re: awk like question
  
  [EMAIL PROTECTED] wrote:
   All,
  
  Hello,
  
   wasn't sure if this was received b/c I got a reurne to sender error.
  
  
   How can I print certain fields delimited by ' '?
   In awk I would write awk '{print $1, $6}' filename
  
  The Perl equivalent of that is:
  
  perl -lane 'print @F[0,5]'
  
   Here is an out file that I want to grab data from :
  
   04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00796   9840S  537
  
   2B0234233543E6A4
   04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00830   9840S  571
  
   D402325A8345ABDE
   04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00066   9840S  127
  
   5202333193B75CBB
   04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00501   9840S  168
  
   4B0233BABA5813F6
  
   I want fields one two and six or the date, time and E string.
   Does it matter whether I use a foreach or a while (filehandle)  ?
  
  You could write that in Perl as:
  
  perl -lane 'print @F[0,1,5]'
  
  John
  --
  use Perl;
  program
  fulfillment
  
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/ http://learn.perl.org/first-response
  
 
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: awk like question

2004-08-13 Thread Jose Alves de Castro
please cc the list

On Fri, 2004-08-13 at 17:21, Errin Larsen wrote:
 ok ... let's say I have an array composed of strings like this:
 
 ## foobar.txt ##
 one  two  three
 A B C
 yes  nomaybe
 
 ##  Perl Script ##
 #!/usr/bin/perl
 use strict;
 use warnings;
 my @myarray = `cat foobar.txt`;
 
 and now I want to put the first two words of each line into a hash, so
 we'd end up with:
 
 my %myhash = ( one=two, A=B, yes=no );
 
 what's a nice, perl - y way of doing that?


perl -nae '$hash{$F[0]}=$F[1]; END{ # do something with %hash}'

That should do the trick


 --Errin
 
 On 13 Aug 2004 16:57:00 +0100, Jose Alves de Castro [EMAIL PROTECTED] wrote:
  On Fri, 2004-08-13 at 16:51, Errin Larsen wrote:
   um, can anyone explain the 'print' function below to me?
  
   specifically ... this:
  
 'print @F[0,5]'
  
  The -a signal splits the input lines and stores the resulting elements
  in @F
  
  Example:
  
  perl -nae 'print $F[1]\n' file.txt
  
  where file.txt contains
  
  one two three
  four five six
  
  prints:
  
  two
  five
  
  Also, although this splitting on spaces, you can also use the -F signal
  to define what you're splitting in.
  
  See `perldoc perlrun`
  
  HTH,
  
  jac
  
  PS:
  
  Oh, print @F[0,5], of course, prints the first six elements of @F, and
  since they're between double quotes, they're joined with whatever is in
  $ (usually a space)
  
  
  
   How do I use this idea in a script instead of a command line?  also,
   how is the input getting into this function?  I mean, I understand $_
   and all, but on a command line, are we piping to that command?  what's
   with the '@F'?
  
   Thanks for the help!
  
   --Errin
  
  
   On Fri, 13 Aug 2004 09:52:04 -0400, [EMAIL PROTECTED]
   [EMAIL PROTECTED] wrote:
Thanks too all who passed some knowledge on, but I ended up using :
   
 while (D) {
   
## look for 9840S and ebexpire
## declare OFS = tab
## tell split to split on IRS 0,15. very similar to awk
print $
   
if (($_ =~ /9840S/)  ($_ =~ /ebexpire, ebexpire/ )) {
 local $, = \t;
print FOO +(split)[0,1,5], $/;
#print +(split)[0,1,5], $/;
   
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145
   
John W. Krahn [EMAIL PROTECTED]
08/13/2004 08:51 AM
   
To: Perl Beginners [EMAIL PROTECTED]
cc:
Subject:Re: awk like question
   
[EMAIL PROTECTED] wrote:
 All,
   
Hello,
   
 wasn't sure if this was received b/c I got a reurne to sender error.


 How can I print certain fields delimited by ' '?
 In awk I would write awk '{print $1, $6}' filename
   
The Perl equivalent of that is:
   
perl -lane 'print @F[0,5]'
   
 Here is an out file that I want to grab data from :

 04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00796   9840S  537
   
 2B0234233543E6A4
 04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00830   9840S  571
   
 D402325A8345ABDE
 04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00066   9840S  127
   
 5202333193B75CBB
 04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00501   9840S  168
   
 4B0233BABA5813F6

 I want fields one two and six or the date, time and E string.
 Does it matter whether I use a foreach or a while (filehandle)  ?
   
You could write that in Perl as:
   
perl -lane 'print @F[0,1,5]'
   
John
--
use Perl;
program
fulfillment
   
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response
   
   
  --
  José Alves de Castro [EMAIL PROTECTED]
http://natura.di.uminho.pt/~jac
  
  
 
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: checking all pieces of split data for NULL

2004-08-10 Thread Jose Alves de Castro
On Tue, 2004-08-10 at 15:01, Tim McGeary wrote:
 I have a file of data that I want to safety check to ensure that there 
 is data for each piece of the line being split.  Is there a fast way to 
 say If any of these are '' then write to error log?

Let's say you have your line split in @line

if (grep /^$/, @line) {

  # then one of them is null

}

 Thanks,
 Tim

HTH,

jac

 -- 
 Tim McGeary
 Senior Library Systems Specialist
 Lehigh University
 610-758-4998
 [EMAIL PROTECTED]
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: Perl oneliner to delete lines from a file

2004-08-09 Thread Jose Alves de Castro
On Mon, 2004-08-09 at 07:34, Ramprasad A Padmanabhan wrote:
 I want to write a command line perl 'script'  to delete one or more 
 lines from a file , by line number

Hi :-)

If I understand correctly, you want to delete lines X to Y from a file,
right?

perl -i -ne 'print unless 1..10' file

that should do the trick :-)


The explanation follows:

-i = in-place edit (you apparently already know what this does
-n = for all lines, apply script
-e = evaluate the following script

print unless 1..10

Well... the '..' operator has been explained every other mail on this
list :-| Basically, this one returns true if you're between lines 1 and
10 (inclusive), which means those lines won't get printed, but all
others will.

HTH,

jac

PS: If you'd like a more detailed explanation of the .. operator or
something else, just say it :-) I'm just not explaining it because
you've probably already read about it here... :-)

 
 for eg in sed I can do the same in two steps 
  
   cat FILENAME | sed -e '1,10d' FILENAME.TMP
   mv FILENAME.TMP FILENAME
 
 The above mechanism has a  lot of pitfalls , like maintaining
 permissions , making sure FILENAME.TMP  does not already exist etc.
 That is why I want to do it with perl -i  
 but I dont want to write a full script for this , because  I am going to
 run it on remote machines ( automated ) , and I cant ftp the script
 everywhere
 
 Any suggestions
 Thanks
 Ram 
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: What is this doing: eval 'exec /usr/bin/perl -T -w -S $0 ${1+$@}' if 0;

2004-08-09 Thread Jose Alves de Castro
On Sun, 2004-08-08 at 04:06, JupiterHost.Net wrote:
 I found this code in a script right after the she-bang line:
 
 eval 'exec /usr/bin/perl -T -w -S $0 ${1+$@}'
  if 0; # not running under some shell
 
 What is it doing?

Hi.

From `perldoc perlrun`, under -S :

Typically this is used to emulate #! startup on platforms that
don't support #!.  This example works on many platforms that have
a shell compatible with Bourne shell:

#!/usr/bin/perl
eval 'exec /usr/bin/perl -wS $0 ${1+$@}'
if $running_under_some_shell;

[ ... etc ... ]

It goes on, so you have a more detailed explanation there...

The line you have is similar enough to that one.

 Its like its executing itself again, but why?
 
 What the heck is: ${1+$@} ??
 
 Wouldn't the eval never get done because of the if 0; ??

Right. Probably your system supports #!, right? :-)

 So why eval a piece of code that willnever be eval'ed ?

I guess the line is still there for some reason... I can think of
several possibilities :-|

 
 Thanks!
 
 Lee.M - JupiterHost.Net
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: File Size Calculator

2004-08-09 Thread Jose Alves de Castro
On Mon, 2004-08-09 at 14:53, David Dorward wrote:
 On 9 Aug 2004, at 14:34, SilverFox wrote:
 
  Hi all, I'm trying to writing a script that will allow a user to enter 
  a
  number and that number will be converted into KB,MB or GB depending on 
  the
  size of the number. Can someone point me in the right direction?
 
 What have you got so far? Where are you stuck? Getting user input 
 (where from)? Working out which order of magnitude the number is?

I wouldn't do that (the part of finding the order of magnitude)... I
would probably keep on doing calculations while the numbers was greater
then 1024... and in the end, when it was, the right letter to append
would be based on the amount of calculations done...

I remember reading something about this on use.Perl ... it was a while
ago, and I'm not sure whether it ever got into a module, but the guy had
written some wonderful code to do this :-)

 Converting between kilo and mega et al? Showing the output?
 
 Show us some code.
 
 --
 David Dorward
   http://dorward.me.uk/
 http://blog.dorward.me.uk/
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: doubt in Definition of sub routine.

2004-08-05 Thread Jose Alves de Castro
On Thu, 2004-08-05 at 11:07, [EMAIL PROTECTED] wrote:
 Hi All,

Hi

 I am using code written by some one else. I didn't understand the difference
 between these subroutines, the way they were defined.
 
 1. sub addToLog  {  Some code  }  Any specific reason where we should
 not use braces ??
 2. sub displayEnv( ) {  }Any specific reason why we should
 use braces  ??
 3. sub trim($) {}Any specific reason why we should
 use a brace with a $ sign  in it ??

Those are prototypes. Basically, you use them to specify how your
subroutine is to be treated.

sub trim($), for instance, means that trim will work on a scalar.

This is useful to, instead of something such as

trim($var)

use something such as

trim $var

Also,

trim

by itself is interpreted as trim($_)

trim $var1, $var2

is the same as

trim($var1), $var2

 sub displayEnv( ) { }

This makes displayEnv by itself (that is, with no braces) work in your
code, not munching up anything following it :-)

 Could some one specify reason when to use braces and when not to use .
 Replies are highly appreciated and thanks in advance for your help.

You're the one who has to choose, I guess :-)

 Regards
 Anand

HTH,

jac


-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: Return values of system

2004-08-03 Thread Jose Alves de Castro
On Mon, 2004-08-02 at 14:52, Prasanna Kothari wrote:
 Hi,

Hi

 [... code ...]

I have tried your code and it works...

 Notice that the code snippet is executing vi with a file and hence 
 editor opens up the file. After typing if I give a wrong vi command for 
 eg: W instead of w; $val gets a value greater than zero(256) and 

This does not happen to me :-|

 hence the else part gets executed. The number of times I give a wrong vi 
 command , the return value gets incremented by 256.
 This snippet is part of a larger program, which opens a editor and asks 
 the user to type in, after the user saves the file contents and exits 
 out of the editor, the program  reads the contents of the file for 
 further processing.
 
 Is there a way to overcome this situation?

Are you sure the problem is in that piece of code? Have you tried
separating it from the rest of code and test it alone? Because that's
what I've done and it works... $val has always been 0 :-|

 Thanks in advance

HTH,

jac

 Prasanna
 
 
 
 
  
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


RE: Cron Tab Implementation

2004-07-08 Thread Jose Alves de Castro
You should take a look at:

Config::Crontab (I found this to be helpful, in the past) and
http://www.webmin.com/ (if memory doesn't fail me, it is written in
Perl, and it may suffice your needs...)

HTH,

jac (back again)

On Thu, 2004-07-08 at 17:53, NandKishore.Sagi wrote:
 Actually I had a lot of time right now at hand and I was trying to spend
 littile time more effectively ;). Anyway I checked that module. It uses
 the basic cron file. This job has to be run on multiple boxes and hence
 rather than depending upon the Cron tab functionality I wanted to
 implement (that is use some existing module :) ) to achieve this. I need
 which would take in time parameters and do the job for me.
 
 Thanks for the quick reply though. Appreciate that.
 
 -Original Message-
 From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, July 08, 2004 11:45 AM
 To: NandKishore.Sagi; [EMAIL PROTECTED]
 Subject: Re: Cron Tab Implementation
 
 
  
  Hi All ,
   
  I want to implement the functionality of crontab in Perl. Which 
  module do you guys suggest can be used. The only consideration is it 
  should be simple to use. That is I should be able to say execute this 
  job at this given time say 1:00 AM . After that I can just go home and
 
  have a nice sleep assured that the job would be kicked off at exactly 
  1:00 AM . I also want this to be executed at every saturday of the 
  week or everyday depending on my requirement.
   
 
 Something wrong with the base cron?  
 
 You might consider:
 http://search.cpan.org/~roland/Schedule-Cron-0.05/Cron.pm
 
 perldoc -f alarm
 perldoc perlipc
 
 http://danconia.org
-- 
José Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informação


signature.asc
Description: This is a digitally signed message part


Re: $^T inconsistant?

2004-07-08 Thread Jose Alves de Castro
Does it vary randomly, or does it just change after a while and stick
with the new value?

I've tried in on my RH and it works fine... :-|

Thoughts, anyone?

jac

On Thu, 2004-07-08 at 17:25, perl.org wrote:
 I am doing something like:
 
 ( $data{sec}, $data{min}, $data{hour}, $data{day}, $data{mon}, $data{year},
 $data{wday}, $data{yday}, $data{isdst} ) = localtime( $^T );
 
 If I do this repeatedly on Windows for one invocation of a Perl script, the
 value of $data{sec} can vary by 1.  Is there an explanation for this?
-- 
José Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informação


signature.asc
Description: This is a digitally signed message part


Re: Program to scan dictionary for words with letters in a particular set?

2004-05-27 Thread Jose Alves de Castro
On Thu, 2004-05-27 at 06:14, Jim Witte wrote:
 Given a file of words W such as 'cat dog at home ...' (or perhaps read 
 into an array, though that would be a very large array), and a set of 
 letters L (a string 'aoeuidhtns' - perhaps put into a array), how would 
 I write a program to extract all words in W whose letters are all in L? 
   I'm thinking of a program to generate a string of words for a 
 typing-tutor program.

Hello, Jim.

I'm sorry if this seems complicated, but it really isn't :-) This is a
one-liner that will do precisely what you want (I hope :-) )

perl -pe 'BEGIN{$r=qr/^[asdfghjkl]+$/}split/ /;$_=join ,grep/$r/,@_'
file

This particular one-liner will search for all words having only letters
from the second alphabetic keyboard row (of qwerty keyboards, at least).


Just to reassure you'll understand what is going on, I'm going to break
the one-liner in some more readable code:

=

#!/usr/bin/perl -pw
use strict;

my $r;

BEGIN {
  $r = qr/^[asdfghjkl]+$/;
}

split / /;

$_ = join  , grep /$r/, @_;

=

...if you can call that readable...

Now lets go step by step :-)

=

#!/usr/bin/perl -pw
# the -p switch will makes all input lines be printed (after being
processed)
use strict;
# I hope you know what this is for

my $r; # this will be our regular expression

BEGIN {
  $r = qr/^[asdfghjkl]+$/;
} # and on this BEGIN block we assign it to be a sequence containing
characters from the mentioned row *only*

split / /;
# here we split the input line by spaces (and the result is put into @_)

$_ = join  , grep /$r/, @_;
# and now we grep the elements that correspond to $r and join them with
spaces

# et voil! the -p switch makes the result be printed

=

HTH :-)

jac

 Jim Witte
 [EMAIL PROTECTED]
 Indiana University CS
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Line number

2004-05-27 Thread Jose Alves de Castro
On Thu, 2004-05-27 at 10:10, Jon Herbry wrote:
 Hi, anybody have idea find the number in a file? Assume I create a file call sample
 and have content below:
 
 Hi, Jame where are you?
 How old are you?
 when you free?
 can you coming my home?
 -
 assume if i want know string word old locate in which line and return the entire 
 sentences, so how i tell perl to find the string for example above? Please help.

If you're using a Unix system, try the command grep. I do believe
MS-DOS like systems include a find utility with the same purpose.

If you're going with Perl, a script like this one will help:

==

#!/usr/bin/perl -nw
use strict;

my $word;

BEGIN { $word = shift || die you must suply a word; }

print if /\b$word\b/;

==

Something like that...

Basically, you take a word and, for each line of input, print it if it
matches the given word (surrounded by boundaries, so Frederick won't
match with Fred :-) )

HTH,

jac

 
   
 -
 Do you Yahoo!?
 Friends.  Fun. Try the all-new Yahoo! Messenger
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Program to scan dictionary for words with letters in a particular set?

2004-05-27 Thread Jose Alves de Castro
On Thu, 2004-05-27 at 11:21, Ramprasad A Padmanabhan wrote:
 On Thu, 2004-05-27 at 15:09, Jose Alves de Castro wrote:
 That was simply neat. I had read in a perl book ' there is always a
 shorter way in perl '. I think this proves it. 
 
 But to think of it there is one hitch
 
 suppose my string is 'god'
 
 Assume
 $word = good
 $r = qr/^[god]+$/
 
 
 then $r would match $word.  Can you think of a good work around ? 

Oh... you want one of each letter only, is that it? Oh boy...

perl -lne 'BEGIN{for(qw(g o d)){$r{$_}++}}split/
/;for(@_){%a=%r;$a{$_}-- for split//;print unless grep $a{$_},keys %a}'
file

As before, I'm gonna tear this down :-)

=
#!/usr/bin/perl -lne
use strict;

BEGIN { for (qw(g o d)) { $r{$_}++} }

split/ /;

for (@_) {
  %a=%r;
  $a{$_}-- for split//;
  print unless grep $a{$_},keys %a
}
=

Now I'm going to explain it (or at least try to...)

=
#!/usr/bin/perl -lne
# the -l switch chomps the line for you, and when you print, it prints
the \n too (for a better understanding of this, perldoc perlrun and then
search for -l)

use strict;
# I don't use this for one-liners, but always use it for scripts

my %r;
BEGIN { for (qw(g o d)) { $r{$_}++} }
# ok, our BEGIN block now holds how many of each letter we want

split/ /;
# we split the input line in words

my %a
for (@_) { # for each word
  %a = %r; # we note how many of each letter we want
  $a{$_}-- for split//; # and for each letter we have, we note down that
there's one less of that letter we need
  print unless grep $a{$_},keys %a
  # if there is any element in the hash %a with a number different from
0, we don't print it
}
=

I hope this is what you wanted :-)

Since this is a beginners list, I'm going to explain this line a bit
further:

$a{$_}-- for split//;

This is the same as:

for (split //) { $a{$_}-- }

Which is the same as:

for (split //, $_) { $a{$_}-- }

Basically, we split the word with an empty regular expression (meaning
we'll get its characters) and for each of those characters we decrement
its corresponding value in %a (even if it doesn't exist, for that
matter).

HTH, :-)

jac

 Thanks
 Ram
 
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: need help(urgent)

2004-05-26 Thread Jose Alves de Castro
On Wed, 2004-05-26 at 11:49, Girish N wrote:
 Hi All
 
 I am stuck with this script which I need to finish today...
 
  
 
 What I am supposed to do is 
 
 1)   parse a file and search for included files and insert those
 included files in the file.
 
 Eg.
 
 File1
 
 Lkdfs
 
 Sdfdsfds
 
 Sdfsdf
 
 Include one.txt
 
 Sdfdsf
 
 Sdfsdf
 
 Werewr
 
 Tytry
 
  
 
 Where one.txt is
 
 A
 
 B
 
 C
 
 D
 
 E
 
 F
 
  
 
 The expected result is
 
  
 
 File2
 
 Lkdfs
 
 Sdfdsfds
 
 Sdfsdf
 
 A
 
 B
 
 C
 
 D
 
 E
 
 F
 
 Sdfdsf
 
 Sdfsdf
 
 Werewr
 
 Tytry
 

Try this:


#!/usr/bin/perl -i -pw
use strict;

s/^Include\s*(.*)/
  open(FILE,$1) || die could not open file $1 ($!)\n;
  while (FILE) {
print;
  }
  close(FILE);
  '';
 /e;


 
 
 
 
 Please help me with this 
 
 Thanks in advance
 
 Girish
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: need help(urgent)

2004-05-26 Thread Jose Alves de Castro
On Wed, 2004-05-26 at 12:09, Jose Alves de Castro wrote:
  What I am supposed to do is 
  
  1)   parse a file and search for included files and insert those
  included files in the file.

Lets get step by step with my solution (just so you understand what it
is doing)

 Try this:

(It's pretty simple)

 #!/usr/bin/perl -i -pw

The -i switch lets you edit the file in-place.
The -p switch prints every line of the file (after running your code on
them)

 use strict;
 
 s/^Include\s*(.*)/

So, you happen to find a statement to include file, you just substitute
it by...

   open(FILE,$1) || die could not open file $1 ($!)\n;

you open the file...

   while (FILE) {

and for each line...

 print;

you print it...

   }
   close(FILE);

then you close it

   '';

and you substitute the line with the Include statement with an empty
line (because -p will have it being printed)

  /e;

the /e switch on the substitution makes your substitution be evaluated
(i.e., instead of having the Include line replaced by something, you
have it replaced by the result of some code)

Now that we got that how of the way, I would also suggest the
substitution starting with something like this:

s/^Include\s*(.*)\n/

(just so it doesn't print an extra line than you expected)

HTH,

jac

-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Array help needed please

2004-05-26 Thread Jose Alves de Castro
On Wed, 2004-05-26 at 12:05, William Kolln wrote:
 This is a previous message from April left unanswered.
 
 
 Can Anyone Help...thanks if you can!
 
 
 
 I have an array called group_vals.
 
 This array can be populated by any combination of values
 e.g.  /sp|lp|ep12|ffp|vid|dvd|bx|bkk|cd|csd/
 
 I want to be able to say that:
 
 if the array contains any combination of only the values 'cd' and/or 'csd'

unless ( grep { !/^(?:cd|csd)$/ } @array) {

# you get all the elements of @array that are neither 'cd' nor 'csd'; if
the resulting list is empty, you enter this block

 then do x
 otherwise
 if the array contains any combination of any other value other than but also

}
elsif ( grep { /^(?:cd|csd)$/ } @array and grep { !/^(?:cd|csd)$/ }
@array) {

# i.e., if the array contains at least one element being 'cd' or 'csd'
and if it also contains something that is not any of them (not sure if I
understood what you wanted, though)

 including 'cd' and/or 'csd'
 then do y

}

 William L Kolln

HTH,

jac

PS: If it doesn't, let us know :-)

-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Array help almost correct

2004-05-26 Thread Jose Alves de Castro
On Wed, 2004-05-26 at 15:07, willy.k wrote:
 Jose
 
 Many thanks for replying so quickly.
 I will explain again, sorry but is complicated.
 
 
 
 ###
  I have an array called group_vals.
 
 This array can be populated by any combination of values
  e.g.  /sp|lp|ep12|ffp|vid|dvd|bx|bkk|cd|csd/
 
  I want to be able to say that:
 
  if the array contains ANY COMBINATION OF ONLY the values 'cd' and/or 'csd'
 
 #Ex 1.  cd
 #Ex 2.  csd
 #Ex 3.  cd csd
 #Ex 4.  cd cd csd
 #Ex 5. csd csd cd
 #Ex 6. cd cd cd cd .upto 10 items
 ###
 # THIS WORKS, thanks#
 #   unless ( grep { !/^(?:cd|csd)$/ } @array) {  #
 ###
 
 
 
 then do x
 }
 elsif
 
 if the array contains any combination of values from the populated group,
 but not cd or csd by themsleves
 
 #Ex 1.  sp
 #Ex 2.  bkk
 #Ex 3.  cd sp
 #Ex 4.  cd bkk lp
 #Ex 5. cd bkk bkk
 #Ex 6. cd sp bkk ep12
 #Ex 7. cd csd bkk lp ep12.upto 10 items
 ###
 # THIS DOES NOT WORK
 #
 # elsif ( grep { /^(?:cd|csd)$/ } @array and grep { !/^(?:cd|csd)$/ }
 @array) {  #
 ###

well, but this will (I hope)

elsif ( grep { /^(?:sp|lp|ep12|ffp|vid|dvd|bx|bkk|cd|csd)$/ } @array and
grep { ! /^(?:cd|csd)$/ } @array ) {

# which fails only if there are other elements in the array that you
don't want or if the array is constituted only by cd's and csd's


This should work, unless I mistyped something... :-)


If you're using /^(?:sp|lp|ep12|ffp|vid|dvd|bx|bkk|cd|csd)$/ more than
once, I would advise this instead:

my $acceptable = qr/^(?:sp|lp|ep12|ffp|vid|dvd|bx|bkk|cd|csd)$/;

and then using $acceptable to do the matchings, such as

grep /$acceptable/, @array


it would be faster and more readable :-)

HTH,

jac

 then do y
 
 
 #
 
 
 
 Thanks
 William
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: get hash from array

2004-05-24 Thread Jose Alves de Castro
On Mon, 2004-05-24 at 13:46, [EMAIL PROTECTED] wrote:
 sub xpto {
my %a = map {$_ = undef} (@_);
return \%a;
 }
 
 or 
 
 sub xpto {
return {map {$_ = undef} (@_)};
 }
 
 
 I'm using this code but shall exist someting clearner without map. Can you
 help me?

If what you want is to clean that, try

sub xpto {
  map {$_ = undef} @_
}

That'll do the trick

If you want to get rid of the map, try this instead:

sub xpto {
  my %b;
  @[EMAIL PROTECTED] = ();
  %b
}

 Thanks

HTH

jac

-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: get hash from array

2004-05-24 Thread Jose Alves de Castro
On Mon, 2004-05-24 at 14:09, Jose Alves de Castro wrote:
 On Mon, 2004-05-24 at 13:46, [EMAIL PROTECTED] wrote:
  sub xpto {
 my %a = map {$_ = undef} (@_);
 return \%a;
  }
  
  or 
  
  sub xpto {
 return {map {$_ = undef} (@_)};
  }
  
  
  I'm using this code but shall exist someting clearner without map. Can you
  help me?
 
 If what you want is to clean that, try
 
 sub xpto {
   map {$_ = undef} @_
 }

sub xpto {
  { map {$_ = undef} @_ }
}

 That'll do the trick
 
 If you want to get rid of the map, try this instead:
 
 sub xpto {
   my %b;
   @[EMAIL PROTECTED] = ();
   %b
 }

sub xpto {
  my %b;
  @[EMAIL PROTECTED] = ();
  \%b
}

Oops... :-) I misread your mail and didn't notice you were looking for a
reference; hence, this update :-)

  Thanks
 
 HTH
 
 jac
 
 -- 
 Jos Alves de Castro [EMAIL PROTECTED]
 Telbit - Tecnologias de Informao
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regex alternation question

2004-05-21 Thread Jose Alves de Castro
On Thu, 2004-05-20 at 21:22, Rich Fernandez wrote:
 I'm unclear about how alternation works in a regex.
  
 Say I want to find either foo or bar within a string. I don't care which
 one I match, only that I make a match.
 Would this be correct:  /foo|bar/
  
 Should they be grouped thusly: /(foo|bar)/
  
 What about /(?:foo|bar)/   ?
  
 Specifically, I know that the second one remembers which one is found and
 the third one doesn't. But is the first example wrong? 


The first one also remembers what is found. It's the variable $
 

 TIA
  
 richf
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: pointer to another list?

2004-05-21 Thread Jose Alves de Castro

For a list of lists, you might want to try http://lists.perl.org/


On Thu, 2004-05-20 at 18:58, JupiterHost.Net wrote:
 Hello group!
 
 Anyone have any idea of a mailing list or more resources about embedding 
 Perl in C like is discussed here:
   http://www-h.eng.cam.ac.uk/help/mjg17/perldoc/pod/perlembed.html)
 
 TIA
 
 Lee.M -JupiterHost.Net
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: matrix solving

2004-05-21 Thread Jose Alves de Castro
Try using Math::Matrix (you can find it on CPAN)


On Fri, 2004-05-21 at 11:18, Boon Chong Ang wrote:
 Hi,
 I want to use perl to do the matrix solving such as matrix inversion and and matrix 
 multiplication, matrix addition and matrix substraction. However, i have no idea how 
 to do it in perl. Any there anyone who can give me some suggestion how to solve this?
  
 
 Thank you  best regards,
 
 ABC
 
  
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regex string modification

2004-05-20 Thread Jose Alves de Castro
On Thu, 2004-05-20 at 01:21, meb wrote:
 Maybe this is because I'm a newbie, or maybe it's because I'm trying to
 modify RSS text. This is a perl script for a web site.
 
 In any case, there's a feed that includes the author at the end of the
 (looong) description. I'd like to limit the decsription to the first 20
 words, add an ellipsis (...) and add the author's name, like so:
 
 These are the first 20 words of this item, and it's really... By Joe Schmo.
 
 
 My regex looks something like this:
 
 (Save 1st 20 words):
 
 /^(\w|\W){20}/g
 
 (Save author tag - always starts with By and ends with period. I think this
 will also ignore periods in middle initials):
 
 /By\s?+\.$/g
 
 
 My problem is that I can't figure out how to modify the string. I've even
 tried $intro + ... + $author, but that didn't work. I also tried a lot of
 different constructions, like ($intro = $fullDesc) =~ /^(\w|\W){20}/g

$intro =~ s/(?=^(\w|\W){20}).*(?=By.*$)/... /;

untested :-)


For replacing something, use

$var =~ s/regular_expression/what_you_want_as_a_replacement/

What I've done was to replace anything having 20 words before and a
By.* after with ... 

To concatenate strings, use a dot (.), like this:

$var = $intro . ...  . $author


HTH,

jac

 If anyone could provide any insight (or a Regex for Dummies page), I'd
 appreciate it.
 
 Thanks.
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regular expr.

2004-05-20 Thread Jose Alves de Castro
On Thu, 2004-05-20 at 12:16, Singh, Ajit p wrote:
 Hello everybody,
 
 My problem is that I have a define a variable which combines two other
 variables with preceeding zeroes.
 
 i.e final_variable :  3 digit var15 digit var2
 
 if var1 is single digit i have to preceed it with two zeroes. eg : 002
 if var1 is double digit i have to preceed it with one zero. eg : 022
 
 Similarly,
 for var2 is single digit i need to preceed with four zeroes .eg :5
 for var2 is double digit i need to preceed with three zeroes .eg :00054
 for var2 is a three digit number i need to preceed with two zeroes .eg
 :00542
 and so on..

This should do the trick:

$var = sprintf(%03i%05i,$var1,$var2);


 can someone pls help me out on the above...
 
 
 
 
 regards,
 
 Ajitpal Singh,

HTH,

jac

-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Query

2004-05-19 Thread Jose Alves de Castro
On Wed, 2004-05-19 at 06:59, [EMAIL PROTECTED] wrote:
 I am using the below command
 
 awk -F: ' $3 ~/bharghav/ { print $0 } ' data.file
 
 but this command produces both
 Vijayb:12345:Vijay B bharghav
 vijaya:12347:vijaya bharghavi
 
 what to if I want only record containing exactly the word bharghav
 that is 
 Vijayb:12345:Vijay B bharghav


If you're trying to get the first line containing bharghav, try this:

perl -ne '/bharghav/  print  exit' input_file


but I'm getting the felling that's not you're looking for... right?

Could we see the input file? (ok, maybe just lines 12345 - 12347)

:-)

jac

-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regexp

2004-05-19 Thread Jose Alves de Castro
On Wed, 2004-05-19 at 15:52, Graf Laszlo wrote:
 Hi

Hi

 I have the following HTML structure:
 
 sm:a
   sm:b
   BBB
   /sm:b
   sm:c
   CCC
   /sm:c
 /sm:a
 
 Every line in this structure is an element of an array,
 named @lines, and I access the elements using a foreach loop.
 
 When I know the tag's name, by example 'sm:a',
 and I need to extract the information contained by 'sm:a'
 and '/sm:a' pair and the tags too, how should I proceed ?
 I tried a regexp like this:
 
 foreach $s (@lines) {
 print $s;
 if($s =~ m|^(sm:a\\n)(.*?)(\\n\/sm:a)$|s){
($l,$c,$r) = ($1,$2,$3);
print OK\n;
print l: '$l'\n;
print c: '$c'\n;
print r: '$r'\n;
 }else{
print HEHE\n;
 }
 }

The problem is that your expression is supposed to be applied to the
whole text, but you're applying it to each line at a time.

Try this:

for (@lines) {
  if ( /sm:a/ .. /\/sm:a/ )
  {
print
  }
}

 Help me. Thank you.

HTH,

jac

-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Query

2004-05-18 Thread Jose Alves de Castro
On Tue, 2004-05-18 at 07:36, Sudhindra Bhat wrote:
 Hi
 
 Thanks. But there is a small issue. Considering the same example, the piece
 of code sent by you prints 123456 which is not on the same line as Test:
 But it doesn't print the characters 123456 ABCDEF which is on the same line
 as Test: 

That's because it is *not* printing the line with Test:... it is only
printing the lines between the one that matches Test: and the one that
matches Results:

This prevents the line with Test: from being printed:  !/Test:/

This prevents the line with Results: from being printed: !/Results:/

Exactly what output were you expecting?
Something like this, perhaps:

===
123456 ABCDEF

123456

(2) 
===

Would that be it?

If so, try 

while (FILE) {
  if ( /Test:/ .. /Results:/ ) {
if ( /Test:/ )   { print $' }
elsif ( /Results:/ ) { print $` }
else { print }
  }
}

HTH,


jac

 Regards,
 Sudhindra
 
 -Original Message-
 From: John W.Krahn [mailto:[EMAIL PROTECTED] 
 Sent: Monday, May 17, 2004 4:56 PM
 To: Perl Beginners
 Subject: Re: Query
 
 On Monday 17 May 2004 03:15, Sudhindra Bhat wrote:
 
  Hi
 
 Hello,
 
  I wanted some help on a piece of code that I was writing. Well the
  requirement is like this. I have a file whose looks like this
 
  (1) Test: 123456 ABCDEF
 
  123456
 
  (2) Results: ABCDEF
 
  Now I want my script to output all the contents between the two tags
  Test and Results. i.e. 123456 ABCDEF 123456. Can someone help me with
  this?
 
 
 while ( FILE ) {
 if ( /Test:/ .. /Results:/ and !/Test:/ and !/Results:/ ) {
 print
 }
 }
 
 
 
 John
 -- 
 use Perl;
 program
 fulfillment
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Query

2004-05-18 Thread Jose Alves de Castro
In that case, with this:

#!/usr/bin/perl -w
use strict;

while () {
  if ( /Test:/ .. /Results:/ and !/Results:/ ) {
if ( /Test:\s*/ ) {
  print $'
}
else {
  print if /./
}
  }
}

you can get that output ( run the script with the input file).

HTH,

jac

On Tue, 2004-05-18 at 12:28, Sudhindra Bhat wrote:
 Hi
 
 This doesn't seem to work. I get a blank output. But yes the output that is
 want is 
 
 123456 ABCDEF
 123456
 
 Regards,
 Sudhindra
 
 -Original Message-
 From: Jose Alves de Castro [mailto:[EMAIL PROTECTED] 
 Sent: Tuesday, May 18, 2004 3:55 PM
 To: Sudhindra Bhat
 Cc: Perl Beginners
 Subject: Re: Query
 
 On Tue, 2004-05-18 at 07:36, Sudhindra Bhat wrote:
  Hi
  
  Thanks. But there is a small issue. Considering the same example, the
 piece
  of code sent by you prints 123456 which is not on the same line as Test:
  But it doesn't print the characters 123456 ABCDEF which is on the same
 line
  as Test: 
 
 That's because it is *not* printing the line with Test:... it is only
 printing the lines between the one that matches Test: and the one that
 matches Results:
 
 This prevents the line with Test: from being printed:  !/Test:/
 
 This prevents the line with Results: from being printed: !/Results:/
 
 Exactly what output were you expecting?
 Something like this, perhaps:
 
 ===
 123456 ABCDEF
 
 123456
 
 (2) 
 ===
 
 Would that be it?
 
 If so, try 
 
 while (FILE) {
   if ( /Test:/ .. /Results:/ ) {
 if ( /Test:/ )   { print $' }
 elsif ( /Results:/ ) { print $` }
 else { print }
   }
 }
 
 HTH,
 
 
 jac
 
  Regards,
  Sudhindra
  
  -Original Message-
  From: John W.Krahn [mailto:[EMAIL PROTECTED] 
  Sent: Monday, May 17, 2004 4:56 PM
  To: Perl Beginners
  Subject: Re: Query
  
  On Monday 17 May 2004 03:15, Sudhindra Bhat wrote:
  
   Hi
  
  Hello,
  
   I wanted some help on a piece of code that I was writing. Well the
   requirement is like this. I have a file whose looks like this
  
   (1) Test: 123456 ABCDEF
  
   123456
  
   (2) Results: ABCDEF
  
   Now I want my script to output all the contents between the two tags
   Test and Results. i.e. 123456 ABCDEF 123456. Can someone help me with
   this?
  
  
  while ( FILE ) {
  if ( /Test:/ .. /Results:/ and !/Test:/ and !/Results:/ ) {
  print
  }
  }
  
  
  
  John
  -- 
  use Perl;
  program
  fulfillment
  
  -- 
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/ http://learn.perl.org/first-response
 -- 
 Jos Alves de Castro [EMAIL PROTECTED]
 Telbit - Tecnologias de Informao
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: using Sleep instead of Cron

2004-05-18 Thread Jose Alves de Castro
On Tue, 2004-05-18 at 16:02, [EMAIL PROTECTED] wrote:
 Hi all,
 
 I'm writing a script which fetches data every hour.  I thought instead of 
 using cron which is platform dependent, to use sleep and a goto statement.  Is 
 there any downfalls to this?

Yes.

With sleep, once the machine is restarted, your process goes away. With
Cron, everything resumes its normal behaviour (and there are probably
other downfalls).

 At the start of the script I check to see if it was ran in the previous hour.
 
 BEGINNING:
 if(open(TIMECHECK, ./synop_daemon_timer.txt)){
  my($cur_sec1,$cur_min1,$cur_hour1,$cur_day1,$cur_mon1) = TIMECHECK;
  my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year)=gmtime(time()); 
  if($cur_hour1 eq  $cur_hour  $cur_day1 eq $cur_day){
   print br SCRIPT IS ALREADY IN ACTION, CANNOT CONTINUE;
   exit(0);
  }
  close(TIMECHECK);
 }

I think this is too much work for something that Cron already does...
are you really going to take your code to a platform without Cron?

 # at the end of the script I write the last time the script was started
 if(open(TIMER, ./synop_daemon_timer.txt)){
  
 my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year,$junk)=gmtime(time()); 
  print TIMER $cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon\n;
  close(TIMER);
 }
 sleep(360);
 goto(BEGINNING);
 
 Thanks 

Take a look at Schedule::Cron

HTH,

jac

-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: using Sleep instead of Cron

2004-05-18 Thread Jose Alves de Castro
On Tue, 2004-05-18 at 16:02, [EMAIL PROTECTED] wrote:
 Hi all,
 
 I'm writing a script which fetches data every hour.  I thought instead of 
 using cron which is platform dependent, to use sleep and a goto statement.  Is 
 there any downfalls to this?

Other downfalls:

- Cron has automatic e-mail sending (should things go awry)

- With Cron, you know it runs every *exact* hour (OTOH, a script started
at 15:15 would keep running at *:15 plus some incrementing delay)

- service crond start / stop / status are a very good way of keeping
track of cron processes. Should you want to stop your script, you would
have to find its process id and kill it; plus, running it again would
make it run some time later/sooner than expected at first (again, cron
resumes normal behaviour).

- others, certainly


 At the start of the script I check to see if it was ran in the previous hour.
 
 BEGINNING:
 if(open(TIMECHECK, ./synop_daemon_timer.txt)){
  my($cur_sec1,$cur_min1,$cur_hour1,$cur_day1,$cur_mon1) = TIMECHECK;
  my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year)=gmtime(time()); 
  if($cur_hour1 eq  $cur_hour  $cur_day1 eq $cur_day){
   print br SCRIPT IS ALREADY IN ACTION, CANNOT CONTINUE;
   exit(0);
  }
  close(TIMECHECK);
 }
 
 # at the end of the script I write the last time the script was started
 if(open(TIMER, ./synop_daemon_timer.txt)){
  
 my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year,$junk)=gmtime(time()); 
  print TIMER $cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon\n;
  close(TIMER);
 }
 sleep(360);
 goto(BEGINNING);
 
 Thanks 
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: inline editing of files, searching for \n\n\n

2004-05-10 Thread Jose Alves de Castro
 The first one does weird stuff

Looks like -i only works with '', not with 'FILE' (though I could
not find that documented).

 Can you tell me how to change the first one to make it work?

If you really need to do that, try 'open(STDIN,$filetobechanged)'
instead. Then, 'while()' instead of 'while(FILE)' and 'print'
instead of 'print FILE'.


Side notes: always use strict :-)

Oh, and if you're just trying to remove \n's, try chomp instead of that
substitution :-) much, much faster :-)

And there are even easier ways, like this one :-)

#!/usr/bin/perl -wl0pi

Right, no code needed :-) The switches do it all :-) Give it a try :-)

HTH

jac

On Mon, 2004-05-10 at 05:22, Timothy Duke wrote:
 Hi,
 
 I have got two versions of a script to eliminate single line-feeds from 
 a file.  The first one does weird stuff - duplicating lines and messing 
 the text file up.  The second one works (I copied it from a Perl guide), 
 but I don't understand why.  I would much prefer the first one to work - 
 Can you tell me how to change the first one to make it work?
 
 Also, I understand that the  operator reads in one line at a time.  If 
 I wish to eliminate only triple line-feeds (\n\n\n) and leave double and 
 single linefeeds, I presume  won't work.  Without reading in the whole 
 file at once, how can I achieve this?
 
 I am using MacPerl.
 
 Thanks for any help!
 
 Tim
 
 
 
 Version #1 (works dreadfullystuffs up the file)
 
 #! perl  -w -i
 $filetobechanged = iBook HD:Desktop Folder:tim.txt;
 open(FILE, + $filetobechanged) ;
 while (FILE) {
  s/\n//g;
  print FILE ;
  }
 close(FILE);
 
 
 Version #2 (works fine)
 $filetobechanged = iBook HD:Desktop Folder:tim.txt;
 @ARGV = ($filetobechanged);
 $^I = .bak;
 while () {
  s/\n//g;;
  print;
 }
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Newbie: regular expression

2004-05-03 Thread Jose Alves de Castro
On Mon, 2004-05-03 at 10:46, Traeder, Philipp wrote:
 chomp might be the easiest (and probably fastest) solution.

True :-) But the '\n' he was looking for was in the middle of the
sentence :-)

BTW, I kept the trailing 'g' in the substitution just because I didn't
knew what the input text might be like... :-)

jac

-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Flag for script

2004-04-16 Thread Jose Alves de Castro
Also, take a look at this:

#!/usr/bin/perl -s
use strict;
our $h;

if ($h) {
  print this is a very special feature;
}

The -s switch interprets -xxx on the command line as a switch and sets
the corresponding variable $xxx in the script to 1. There's also
something else, which I leave for you to discover... ;-) You know what
they say, man perlrun!! :-)

I usually use something like this, actually:

die this is the help text
blah blah blah
 if $h;

HTH

Regards,

jac



On Thu, 2004-04-15 at 20:10, Jakob Kofoed wrote:
 Hello All,
 
 I'm trying to create a script with where you can put a flag to the script or
 not
 fx run it like:
 
 script -h
 or just
 script
 
 something like:
 
 if ( $ARGV[0] =~ /-h/ ) {
 print You have chosen the very special ability!\n;
 } else {
 print you have not chosen the very special ability!\n;
 }
 
 but when I run this one without any flag i get an error message:
 use of initialized value in pattern match (m//)
 
 Do I have to do it differently to get rid of the error?
 
 Thanks,
 Jakob
-- 
Jos Alves de Castro [EMAIL PROTECTED]
Telbit - Tecnologias de Informao


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response