Accessing array from Perl DBI using Template Toolkit

2010-08-09 Thread me @
Hi, I'm trying to pickup CGI web application programming using Perl, DBI 
TT (Template Toolkit). This small application is about storing data (using
CGI::FormBuilder) list it using Template Toolkit. After retrieving records
from MySQL using DBI, I've problem understanding how to pass to Template
Toolkit, even though I've managed make it work by copy some code from Perl
Mongers  Template Toolkit's tutorial. Below are my codes :

 start of list.cgi 
#!/usr/bin/perl

use warnings;
use strict;
#use diagnostics;
use Template;
use DBI;

my %kar;
my $tt_file='list.tt';

my $tt = Template-new({
INCLUDE_PATH = './tt',
}) || die $Template::ERROR\n;

my $vars = {
kars= \%kar,
};

sub db_select {
my ($dsn,$dbuser,$dbpass,$dbh,$plh_reg_no,$sth,$reg_no,$brand,$cc);
$dsn = dbi:mysql:database=mycars:hostname=127.0.0.1;
$dbuser = driver;
$dbpass = plaintext;
$dbh = DBI-connect($dsn,$dbuser,$dbpass)
or die cannot connect to database : $DBI::errstr;

$plh_reg_no = car%;
$sth = $dbh-prepare(SELECT reg_no,brand,CC FROM auto_details WHERE
reg_no like ?);
$sth-execute($plh_reg_no)
or die Cannot execute statement : $DBI::errstr;

while (($reg_no, $brand, $cc) = $sth-fetchrow_array()) {
$kar{$reg_no} = {
reg_no  = $reg_no,
brand   = $brand,
cc  = $cc
}
}
$dbh-disconnect();
}

db_select();

$tt-process($tt_file, $vars)
|| die Template process failed: , $tt-error(), \n;
 end of list.cgi 

 start of list.tt 
Content-type: text/html


[% PROCESS header %]
Form strongList/strong
p
ul
[% FOREACH kar IN kars.values %]
li[% kar.reg_no %], [% kar.brand %], [% kar.cc %]/li
[% END %]
/ul
/p
[% PROCESS footer %]
 end of list.tt 

My question :
- I suppose the above code convert array into hash and pass it to TT, is
there any other way then this because I find that the line noise is a bit
too much.
- I've read about some where on some website that arrays passing to TT
should always use array reference ($sth-fetchrow_arrayref) instead of the
above, using arrays ($sth-fetchrow_array). If this were to use array
reference, can someone show some codes to me so that i may check it out and
try to understand.

Thanks in advance,
Edward.


HELPPPPPPPPPPPPPP

2008-07-27 Thread THE WORLDS GOIN TO FAST FOR ME
please help me,this is what i put ,tell me what im doin wrong


Restricted Directory or URL:  http://www.googlepages.com


Authentication URL:  http://www.googlepages.com


Authentication method:  POST


Parameters:   AttributeValue
i put ..  full name  google454543html


   password google454543html
---­
could it be how my webpage name is ???
www.mywebsitename.googlepages.com



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




Re: changing the group that files are created with

2006-09-18 Thread Jack Faley ( Who's going to take me serious without a laser pointer?)

On 9/18/06, Ken Foskey [EMAIL PROTECTED] wrote:



I have a lot of files created by a (much too) complex script and the
user I am running with has a default group of 'staff' but I want all
files created to have clientgrp which we create to ensure that only
authorised people have access to a particular clients data.  I have a
command in Linux that does this but I am running on AIX  (I want it
portable so a pure perl method is better...)

MY solutions are chgrp on the file after creation.  Great initially but
then someone will forget for a new file and besides it adds a lot more
code and the complexity goes up.  I ended up adding the group to the
directory with g+s to force the group but there may be a time were we
use common directories and the file should be protect there as well.

I cannot google an answer because there are too many answers and I
cannot figure out how to fine tune my query.


I want to change the group files are created with and I cannot google an
answer because I get too many answers.

Thanks
Ken Foskey

I'm not sure I understand. It appears you don't want to ( or can't) change
the default group of your id so they are created with this group? You don't
want to use chown -R or chgrp -R on directories after the fact? What about
in the program before it finishes?



How exactly do you identify this is a file that should have this special
group? When the file is initiallly created I'm guessing you shouild set
correct ownership then. If you are trying to do it after  the fact then you
will need to find something unique about these files to search on then issue
the correct ownsership.
I think I'm missing a piece of this question. And why does your command in
Linux not work in AIX? Are you running current AIX?


Re: File::find with no_chdir

2006-09-18 Thread Jack Faley ( Who's going to take me serious without a laser pointer?)

On 9/18/06, Emilio Casbas [EMAIL PROTECTED] wrote:


Hi,

I have this script;

---
use File::Find;

$File::Find::no_chdir = 0;
find(\wanted, @ARGV);

sub wanted {
print $File::Find::name\n if(-d);
}

---

I want to do a directory search for a given ARG, but no a recursive
search, for example
this script show this;

[EMAIL PROTECTED] tmp]# perl script.pl /tmp
/tmp
/tmp/.ICE-unix
/tmp/test_directory
/tmp/test_directory/directory1
/tmp/test_directory/directory1/directory2
/tmp/test_directory/directory1/directory2/directory3
/tmp/lost+found
/tmp/.font-unix

But i want a behaviour like this command;
[EMAIL PROTECTED] tmp]# find /tmp -type d -maxdepth 1
/tmp
/tmp/.ICE-unix
/tmp/test_directory
/tmp/lost+found
/tmp/.font-unix

Any help?

Thanks
Emilio C.



I believe you want to use the Prune option. This covers it with an earlier
example:
http://groups.google.com/group/comp.lang.perl.misc/browse_thread/thread/7ffb588d4a3e67d/21c98bb6a9984979?lnk=stq=%24File%3A%3AFind%3A%3Aprunernum=1#21c98bb6a9984979


There isn't Close FH

2005-11-15 Thread It's from me !
In book located at
http://learn.perl.org/library/beginning_perl/3145_Chap06.pdf
wich is about Chapter 6: Files and Data isn't
mentioned about Close which is for closing those
opened files. Thought this might be usefull to notice
you about this.

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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




Regex problems

2004-08-23 Thread me
Hello all,

I have been beating my head against the wall for a
while trying to extract some data.

Here is the following data:

SNIP
===
Data 1: data1
Data 2: data2
Data 3: data3
Data 4: data4
Data 5:
data5 data5 data5 data5 
data5 data5 data5 data5 
data5 data5 data5 data5 


SNIP

My goal is to put all data after each colon into a
variable.

I don't have any problem with Data 1 through Data 4. 
My problem is when I get to Data 5:, I can't figure
out how to put the data into a variable.

I'll spare you the details of my all my failed
attempts.  Everything I've tried fails miserably.

Any help would be greatly appreciated.

Thanks,
Kyle





__
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo 

-- 
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 help

2002-04-02 Thread Me

 i have a date string formatted this way:  $date = Apr. 02, 2002
 i want to capture the Apr (without the period) into $1, 02 into
$2, and
 2002 into $3.
 note that some months may not be abbreviated (such as May), and
therefore
 might not have a period.
 my regex skills are still sadly inferior (though i'm learning =)

Hmm. What doc are you learning from? What have you tried
for the above?

 my second (and optional) problem for you to solve: i want to transform
this
 into mysql date format (-mm-dd). this is easy enough to do, but i
was
 wondering if there are any modules there that can date manipulation a
lot
 easier. if you know any, just let me know.

Perl's got a huge community supported module library
called cpan. For more info, enter at a command prompt:

perl -q cpan

As this doc will tell you, there's a search.cpan.org.
With it you can easily browse/search the entire library.

hth

--
ralph


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




Linux Commands in perl

2001-11-01 Thread me

Whats the trick in running linux commands under perl?

Mike



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




Re: Linux Commands in perl

2001-11-01 Thread me

Thanks!


Richie Crews [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 system(rm -rf /);

 On Thu, 2001-11-01 at 10:59, [EMAIL PROTECTED] wrote:
  Whats the trick in running linux commands under perl?
 
  Mike
 
 
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 --
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

 Richie Crews

 Unix Administrator / Internet Integrator

 Email: [EMAIL PROTECTED]

 Cell: (706) 773 - 3436
 Desk: (706) 634 - 3681
 Fax: (706) 634 - 3831

 When I take action, I'm not going to fire
 a $2 million missile at a $10 empty tent
 and hit a camel in the butt. It's going to
 be decisive.   -  President George W. Bush


 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-




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




Re: Linux Commands in perl

2001-11-01 Thread me

I know I wasnt about to run that one :)
Chris Spurgeon [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Yow!  Just a quick note to the differently clued, you really don't want to
 run that example.  Maybe do something like

 system(ls -lt /);

 instead.
 
 Chris Spurgeon
 Senior Design Technologist
 [EMAIL PROTECTED]

 ELECTRONIC INK
 One South Broad Street
 19th Floor
 Philadelphia, PA 19107
 www.electronicink.com

 t 215.922.3800 x(233)
 f 215.922.3880


 -Original Message-
 From: Richie Crews [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, November 01, 2001 11:01 AM
 To: [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: Re: Linux Commands in perl


 system(rm -rf /);

 On Thu, 2001-11-01 at 10:59, [EMAIL PROTECTED] wrote:
  Whats the trick in running linux commands under perl?
 
  Mike
 
 
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 --
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

 Richie Crews

 Unix Administrator / Internet Integrator

 Email: [EMAIL PROTECTED]

 Cell: (706) 773 - 3436
 Desk: (706) 634 - 3681
 Fax: (706) 634 - 3831

 When I take action, I'm not going to fire
 a $2 million missile at a $10 empty tent
 and hit a camel in the butt. It's going to
 be decisive.   -  President George W. Bush


 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 This e-mail is intended solely for the above-mentioned recipient and it
may
 contain confidential or privileged information.  If you have received it
in
 error, please notify us immediately and delete the e-mail.  You must not
 copy, distribute, disclose or take any action in reliance on it.  In
 addition, the contents of an attachment to this e-mail may contain
software
 viruses which could damage your own computer system.  While Electronic
Ink,
 Inc. and E Ink Ltd have taken every reasonable precaution to minimize this
 risk, we cannot accept liability for any damage which you sustain as a
 result of software viruses.  You should perform your own virus checks
before
 opening the attachment.



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




Re: [NEWBIE-Question] Processing Menus

2001-11-01 Thread me
o
do is have it email me all the info, which it does email me.
Everything but
the dropdown menu information.  see attached.
   
Thanks again...
   
Mike
   
   
   
Curtis Poe [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 --- [EMAIL PROTECTED] wrote:
  Hello all,
 
  I am trying to process a menu option but for some reason perl
causes the
  value to come up blank can anyone help? This is only hapening on
the
menu
  items.
 
  Is there a trick to sending drop down menus?
 
  TNX,
 
  Mike

 Mike,

 What do you mean by menu?  Are you referring to Perl::Tk menus?
Win32::Gui?  Perhaps you mean
 select drop-downs from HTML?  Can you post some sample code?  We
need a
lot more information
 before we can help you.

 Show us what you have.  Tell us what you expect.  Tell us what you
are
actually getting.  That's
 usually a good start.

 Cheers,
 Curtis Ovid Poe

 =
 Senior Programmer
 Onsite! Technology (http://www.onsitetech.com/)
 Ovid on http://www.perlmonks.org/

 __
 Do You Yahoo!?
 Make a great connection at Yahoo! Personals.
 http://personals.yahoo.com
   
   
   
   
[Add your link]
[ Home ] [ Up ]
   
 
  --
  
 Category:  URL:
  
 Email:
  
 (Note: Your email will only be used to notify you when your link
 has been added.)
  
   
--
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]




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




Re: [NEWBIE-Question] Processing Menus

2001-11-01 Thread me
;
print MAIL Description: $in{'description'}\n;
close(MAIL);
   
Thanks again
   
Mike
   
Etienne Marcotte wrote:
   
 The CGI (or other parsing sub) reads the data selected from the
drop
 down, which is in the value part of each option tag.

 select name=dropdown
 option value=1option 1/option
 option value=2option 2/option
 option value=3option 3/option
 /select

 then in your param{'dropdown'}you should have 1, 2 or 3 depending
on
  the
 option that he choose.

 What are you using to parse the data? CGI.pm ? That is probably
  causing
 the problem because your html seems right

 Etienne

 Bogus email wrote:

  Sorry bout that... I do mean select drop-downs from HTML. What
I
  want to
  do is have it email me all the info, which it does email me.
  Everything but
  the dropdown menu information.  see attached.
 
  Thanks again...
 
  Mike
 
 
 
  Curtis Poe [EMAIL PROTECTED] wrote in message
  [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
   --- [EMAIL PROTECTED] wrote:
Hello all,
   
I am trying to process a menu option but for some reason
perl
  causes the
value to come up blank can anyone help? This is only
hapening on
  the
  menu
items.
   
Is there a trick to sending drop down menus?
   
TNX,
   
Mike
  
   Mike,
  
   What do you mean by menu?  Are you referring to Perl::Tk
menus?
  Win32::Gui?  Perhaps you mean
   select drop-downs from HTML?  Can you post some sample code?
We
  need a
  lot more information
   before we can help you.
  
   Show us what you have.  Tell us what you expect.  Tell us what
you
  are
  actually getting.  That's
   usually a good start.
  
   Cheers,
   Curtis Ovid Poe
  
   =
   Senior Programmer
   Onsite! Technology (http://www.onsitetech.com/)
   Ovid on http://www.perlmonks.org/
  
   __
   Do You Yahoo!?
   Make a great connection at Yahoo! Personals.
   http://personals.yahoo.com
 
 
 
 
  [Add your link]
  [ Home ] [ Up ]
 
   
--

   Category:  URL:

   Email:

   (Note: Your email will only be used to notify you when your
link
   has been added.)

 
  --
  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]
  
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]



begin 666 addlink.htm
M/$M+2!S879E9!FF]M('5R;#TH,# R,BEH='1P.B\O:6YT97)N970N92UM
M86EL(TM/@T*/%$3T-465!%($A434P@4%53$E#((M+R]7,T,O+T141!(
M5$U,(#0N,!4F%NVET:6]N86PO+T5.(CX-CPA+2T@V%V960@9G)O;2!U
MFP]*# P-#8I:'1T#HO+VUI8VAA96QPF%T=YD6YU+F-O;2]C;%SR]!
M91L:6YK+FAT;2 M+3X-CQ(5$U,/CQ(14%$/CQ4251,13Y.97@4%G92 Q
M/]4251,13X-CQ-151!(AT=' M97%U:78]0V]N=5N=U47!E(-O;G1E
M;G0](G1E'0O:'1M;#L@8VAAG-E=#UW:6YD;W=S+3$R-3(B/@T*/$U%5$$@
M8V]N=5N=#TB35-(5$U,(#4N-3 N-#@P-RXR,S P(B!N86UE/4=%3D52051/
M4CX-CQ-151!(-O;G1E;G0]1G)O;G1086=E+D5D:71OBY$;V-U;65N=!N
M86UE/5!R;V=)9#X\(2TM;7-T:5M92TM/CQ,24Y+( T*:')E9CTB861D;EN
M:U]F:6QER]T;W!O,3$Q,2YCW,B('1Y4]=5X=]CW,@F5L/7-T6QE
MVAE970^#0H\345402!C;VYT96YT/2)T;W!O(#$Q,3$L(1E9F%U;'0B(YA
M;64](DUI8W)OV]F=!4:5M92(^#0H\345402!C;VYT96YT/2)T;P@95F
M875L=(@;F%M93TB36ECF]S;V9T($)OF1EB(^/](14%$/@T*/$)/1%D^
M/$M+6US;F%V:6=A=EO;BTM/@T*/%1!0DQ%(-E;Q3%C:6YG/3 @8V5L
M;%!A91I;F],!W:61T:#TB,3 P)2(@8F]R95R/3 ^#0H@(#Q40D]$63X-
MB @/%12/@T*( @(#Q41#X-B @( @(#Q0(%L:6=N/6-E;G1ECX\1D].
M5!S:7IE/38^/%-44D].1SX\24U'(AE:6=H=#TV,!A;'0](D%D9!Y;W5R
M(QI;FLB( T*( @( @W)C/2)A91L:6YK7V9I;5S+T%D9QI;FLN:'1M
M7V-M%]T;W!O,3$P7V)NBYG:68B('=I9'1H/38P, -B @( @()OF1E
MCTP/CPO4U123TY'/CPO1D].5#X\0E(^/$Y/0E(^6R9N8G-P.SQ!('1AF=E
M=#TB(B -B @( @(AR968](FAT=' Z+R]M:6-H865L')A='0N9'EN=2YC
M;VTO8VQAW,O(CY(;VUE/]!/B9N8G-P.UT\+TY/0E(^( T*( @( @/$Y/
M0E(^6R9N8G-P.SQ!('1AF=E=#TB(B -B @( @(AR968](FAT=' Z+R]M
M:6-H865L')A='0N9'EN=2YC;VTO8VQAW,O;EN:W,N:'1M(CY5#PO03XF
M;F)S#M=/].3T)2/CPO4#X\+U1$/CPO5%(^/$M+6US;F%V:6=A=EO;BTM
M/CPO5$)/1%D^/]404),13X\(2TM;7-N879I9V%T:6]N+2T^#0H\5$%3$4@
M9ER/6QTB!C96QL4W!A8VEN9STP(-E;Q0861D:6YG/3 @=VED=@](C$P
M,4B()OF1ECTP/@T*( \5$)/1%D^#0H@(#Q44CX-B @( \5$0@=D%L
M:6=N/71O!W:61T:#TB,24B/CPO5$0^#0H@( @/%1$('9!;EG;CUT;W @
M=VED=@],C0^/]41#X\(2TM;7-N879I9V%T:6]N+2T^#0H@( @/%1$('9!
M;EG;CUT;W ^/$M+7=E8F)O=!3U0](D=E;F5R871E9%-CFEP=(@4%)%
M5DE%5STB((@W1AG1S%N(TM/@T*( @( @/%-#4DE05!L86YG=6%G
M93U*879A4V-R:7!T('1Y4]=5X=]J879AV-R:7!T/CPA+2T*9G5N8W1I
M;VX@1G)O;G1086=E7T9OFTQ7U9A;ED8

[NEWBIE-Question] Processing Menus

2001-10-31 Thread me

Hello all,

I am trying to process a menu option but for some reason perl causes the
value to come up blank can anyone help? This is only hapening on the menu
items.

Is there a trick to sending drop down menus?

TNX,

Mike



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




Re: $a = $b eq ? 1 : 0;

2001-10-30 Thread Me

  $allowed = $username eq 'admin' ? 1 : 0;
  
  $allowed = 1 if $username eq 'admin';
 
 FWIW, that statement by itself has no relationship to mod_perl.

Well, I think the point is that mod_perl doesn't reset the value
of variables between runs so the second line may not do what
the programmer intended in a mod perl environment.


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




Re: Can i able to access the C function from Perl.

2001-09-25 Thread Me

Subject: Can i able to access the C function from Perl.

owtdi: http://search.cpan.org/doc/INGY/Inline-0.43/C/C.pod


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




Re: Security Mechanisms with Perl/Apache on an Hosted Website???

2001-09-25 Thread Me

fmteyewtka remote authentication: http://library.smc.edu/rpa.htm

 Hey folks,
 I'm trying to cobble together some form of authentication mechanism on
a
 website I am building for a friend. His ISP uses Perl  Apache (it's
on a
 linux box). I (obviously) don't have root priviledges and have limited
 access to the filesystem. What are my options (if any)??? I think some
form
 of session management would go hand-in-hand with the authentication.



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




Re: Selective Joining of Two Array Elements

2001-09-25 Thread Me

 I have this list I've read into an array line by line:
  tty 81   bcain  Async 01:18:35  00:02:55
  tty 83   dnguyenAsync 00:20:27  00:01:13
  tty 85   cmandeville \
  Async 03:26:22  00:00:58
  tty 88   twootenAsync 02:00:36  00:00:30
  tty 89   jwatersAsync 00:13:37  00:00:32
  tty 95   epastoriza Async 00:45:29  00:00:00


 The line starting with tty 85 is continued on the line after it so I'd
 like to join them and close up the array. Any suggestions?

Something like:

@b = map { /\\$/ and $h=$_, undef or $_=$h.$_, undef $h, $_ } @a;

I haven't tested this; you may need to play with brackets to ensure
correct precedence.

map does the bit of code in {} for each element of @a. before
the {} block starts each time, $_ is set to the element of @a.
the result of the {} is added to @b.

gotta run.


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




Re: Continuing a while loop

2001-09-20 Thread Me

 I need the code below to execute the sub double_check($host) but I
still
 want the while loop to continue exactly what it's doing.

 Is this possible with Perl|?

 while (1) {
  $p   = Net::Ping-new(icmp, 4, 2);  #Ping object.  Uses icmp
 protocal
  foreach $host (sort keys (%host)) {
  unless ($p-ping($host)) {
 $name = $host{$host}; #Name of the machine/host
 delete $host{$host};
 double_check($host);
 }
   }
 }

Yes. After a sub call is done, execution continues immediately
after the point where the sub call occured. Every language I
know that uses the term 'sub' uses it to mean a 'subroutine'
that does something then continues execution immedately
after the point it was called.

I note that you assign to $name but never use it. Are you using
the -w switch?

In general, if you are wondering if something works, the right
thing to do is to try it, experiment a bit, try to work out the bugs
yourself, and only post to the list if you are stuck.

hth.


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




Re: Perl one-liner problem

2001-09-08 Thread Me

[on list]

 On Apache Unix, this just hangs and does nothing and I have to do
control d to kill it!

  perl -wpi.org -e s@/cgi-bin/forum_idx.pl@/fakecgi/fakeforum_idx.pl@

It doesn't hang, it's waiting for input.

Other notes:
1. A backup file given .org as its extension? Weird. Most people use
.bak.
2. You haven't used /g, so you'll won't replace globally, you'll
just replace the first occurence.
3. You haven't used /i, so you'll won't ignore case.

The above suggests:

perl -wpi.bak -e
s@/cgi-bin/forum_idx.pl@/fakecgi/fakeforum_idx.pl@gi foo*

to globally search and replace, ignoring case, in files whose name
begins with foo in the current directory, and creating backups of
the files (pre-change) called foo*.bak


PS. Please keep email on list unless it is not appropriate for the list.


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




Re: Perl one-liner problem

2001-09-07 Thread Me

 Any idea why this aint working?
 
 perl -wpi.org -e s@/cgi-bin/forum_idx.pl@/fakecgi/fakeforum_idx.pl@

no quotes around the string to be evaluated (the s@...@...@ bit).




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




Re: source code !

2001-09-07 Thread Me

 $array[112]='a';
 but there isnot any array with this name.why?

1. perhaps the programmer made a mistake. execute perl with -w
to find out more.

2. the array name is @array. are you sure there isn't an @array?

3. you merely have to mention a variable or element of an array
or hash, and it will spring into existence as necessary (occasionally
when you might not expect, but mostly it does what you expect).


 and for initialize the array,what is the meaninig of  '\' in 
 %array(id=\$var)

a reference to $var

say $var is 5 when you do the above line.

if you then say:

$foo = \$var;
print $$foo;

you get 5.

if you then do:

$var = 6;
print $$foo;

you get 6.



hth


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




Re: Where are the printf function formatting options / rules?

2001-09-02 Thread Me

 print formatted text.  I have been unable to find a comprehensive list
of
 formatting options for use with this function.  Does anyone have a
link to
 one?

 Also, how do I access the perl manpages from the command line.

perldoc -f sprintf
perldoc perl

hth



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




Re: How to count the number of whitespaces at the start of a line

2001-08-20 Thread Me

 count only the number of spaces at the START of the line

OWTDI:

$_ = '  test ';
/^( *)/;  # the parens capture the match into $1
print length $1;

---

In case you are interested, you tried:

 my $i = () = $str =~ /^\s/;

This would print 0 or 1, depending on whether the regex matched.

$i in your approach is counting the number of chunks matched,
not the length of any of the matched chunks.

To explain this a little further, consider instead:

my $i = () = $str =~ /^(\s)/;

This would also print 0 or 1, depending on whether the regex matched.
All I have done is added explicit capturing parens which were, in your
code, assumed by perl.

Now consider:

my $i = () = $str =~ /^(\s)(\s)/;

This would print 0 or 2, depending on whether the regex matched,
which it would if there was at least two spaces at the start of the
line.

hth


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




Re: Problem with open(....?) ....??

2001-08-19 Thread Me

 I have a script that has to traverse a path to get to a file to open 
 it. I do not own that file but the permissions are set to 644, so 
 I should be able to open it with my script. When I run the 
 script with the web browser, I get No such file or directory.

The web server runs CGIs as a particular user, typically
something like 'nobody'. It could be that that user's
priveliges, or the priveliges in general of users that
aren't you, are insufficient for what you want.

Are you the owner of the file? Are you the owner, or in the
group, of any of the directories leading to the file?


 But when I run the script from the console like,
 perl myscript.cgi
 it opens the file and reads it.

This is presumably being executed as you which
makes a big difference.


 Does the script need special permission to see the file 
 and directory, when run through the web browser ??

It needs to have its user, which the server admin can tell
you, have the right permissions.


hth.


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




Re: untainting passwords

2001-08-19 Thread Me

 Hi, can someone tell me the proper syntax for untainting a UNIX
password?

First, just in case there is any confusion, I don't believe there is
anything special about passwords in the context of tainting.


 if ($password_T =~ /(  )/) {$password = $1;} else {$password=' ';}

 What goes in the ( ) ?

Something that matches (or fails to match) the password part of
the $password_T string.

sermon
The way you pose this question suggests you are hacking around
the security built in to some perl code that someone else wrote
when you have little care or clue about either security or perl. That
way lies madness...
/sermon

hth.


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




Create html extract from plain text file (was Re: How can i read out data from a file ?)

2001-08-09 Thread Me

 I´d like to know how i can read out data from a file with
 for example, a newsletter, like

1.) first news
2.) 2nd news
3.)...

and print it out as html ? How do i only print sentence no.2 ?

First, some questions about what you already know.
Do you know:
Basic perl?
Basic HTML?
How to use perl to read lines from a file?
How to use perl modules?
CPAN?
perldoc?

And about your data/task:
Is it plain text?

Is this a once-off to translate some already existing documents
of which there will be no more, or one that will be repeatedly
applied to some ongoing supply of 100's of newsletters?

Is the newsletter's content created 100% manually, or by dropping
text in to template / or programatically generated?

--

Some quick examples of reading a text file, a line at a time:

while () { # read next line

if $. == 2 { ... # if line number 2 then

if /foo/ { ... # if line contains 'foo'

if /^foo/ { # if line starts with 'foo'

if eof { ... # if end of file

print; # print line
}

There's a zillion ways to do the output bit.

One way would be to use Text::Template, but it partly depends
on what you know and what you're trying to do.





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




Re: getting the calling function name.

2001-08-07 Thread Me

 caller only gives only the name of current sub

You didn't read the docs carefully enough...

caller($calldepth)

perldoc -f caller


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




Re: getting the calling function name.

2001-08-07 Thread Me

[Rajeev, please keep beginner topics on the list]

 Thanks again

You're welcome :

 But how to calculate the $calldepth value here.

 Actually I tried with the values for $i or $calldepth as given in the
docs.

(Note that I just made up the variable name $calldepth.)

 I understand that 1 represents the first level of call. and 2 second.
 In can of recursions and loops how can we keep track of just previous
 level here?

Er, that's 1. The call depth goes backwards.
0 = current sub
1 = caller (sub that called the current sub)
2 = caller's caller (sub that called the sub that called the current
sub)

Also, Be aware that the optimizer might have optimized call frames
away before `caller' had a chance to get the information.

hth

 with regards

 Rajeev Rumale


 - Original Message -
 From: Me [EMAIL PROTECTED]
 To: Rajeev Rumale [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Tuesday, August 07, 2001 2:53 PM
 Subject: Re: getting the calling function name.


   caller only gives only the name of current sub
 
  You didn't read the docs carefully enough...
 
  caller($calldepth)
 
  perldoc -f caller
 
 



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




Re: getting the calling function name.

2001-08-06 Thread Me

perldoc -f caller
perldoc Carp.pm
http://search.cpan.org/search?mode=modulequery=assert

 Hello Every Body,

 I need some help.
 I am using a sub routine to log all the messages to be used for
debugging
 purpose.
 ie. debugLogger($debug_message);
 Since very similare kind of messages are genrated at serveral places,
I add
 the function name.
 i.e., debugLogger(inside x  \n $debug_message);

 I feel it would be better as a prgramming style if sub debugLog is
able to
 find the name of the calling function or the name of the function
 calling this sub and genrate the appropriate message.


 with regards


 Rajeev Rumale


 ***
  The human race has one really effective weapon, and that is
laughter.
 ***



 --
 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: split problem

2001-08-05 Thread Me

 What's the problem with my split?

 $line = "var=value";
 ($var, $value) = split(/\s*[=]\s*/, $line);

Looks fine to me.

 I experienced that $var and $value contained the first letter of the
var and
 the value. Sometimes  nothing. Where is the error?

Looks to me like it must be in your input.


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




Re: Insecure, dependant and tainted:(

2001-08-04 Thread Me

 Insecure, dependant and tainted:(

Heh. Perl can be a bit brutal at times...


 if ( open( FD, $Globals::DATA/$site/$Globals::REFTALLY )) {

#**Error occurs here (on open)***
 if ( open( FD, $Globals::DATA/$site/$Globals::REFTALLY )) {

 Insecure dependency in  open while running with -T switch at

perl is being run with the -T switch. This means you are running in
taint mode. Taint mode means data that you get from outside
your program is untrusted and untrusted data is marked -- tainted.
You can not send tainted data, directly or indirectly, back outside
your program. Any data whose value might be affected by tainted
data is itself tainted.

Solutions:

1. Turn taint checking off. (And your code becomes insecure to the
extent that outside data should not be trusted and your use of that
data is open to abuse.)

2. Turn tainting off for the FD filehandle. (And your code becomes
insecure to the extent that data from that file should not be trusted
and your use of that data is open to abuse.) See FileHandle.pm.

3. Process the data to verify it is ok, then untaint it bit by bit as
appropriate. (And your code is insecure to the extent that you
screw up.)

See

perldoc perlsec

hth


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




Re: (MORE INFO) loose matching with regex

2001-07-28 Thread Me

 Like I said I know I can use the module Similarity. But in
 order to do this I would need bot the query and the subject
 string. And to get the subject string I would need to 'slide'
 down the larger string and pull out all combinations 1 by 1.
 This is very slow with a 4.5 million character string. I'm just
 looking for a way to speed things up.

You might want to use a variant of Boyer-Moore's algorithm.

Dunno how best BM could be fitted to your case, but I am
pretty sure some variant would work, and could, in principal
at least, give you something like a 100 to, what, 10,000?,
fold speed up.

BM basically has you match the substrings backwards and
take advantage of what you know when this fails. Some
variants add a twist that focuses on elements of the
substring that are (likely to be) infrequent in the large
string.

Here's a simplified version of BM that ignores the fuzzy
aspects of your search:

search for 'efghmnop'
in 'abcdefghijklmnopqrstuvwxyzabcdefghmnop'

Take the last letter of the searched for substring, p.

Pick a possible substring endpoint in the large string.
This starts out at an offset from the beginning of the
large string. The offset is the length of the substring.

So, in the above case, you start by comparing p and h.

That fails. Next, given that there is no l in the substring,
you move the end point in the large string forward to the
length of the substring past the l. Then, because you
also know that that is followed by mnop, and the first
4 characters of the substring are not mnop, you move
the endpoint forward by another 4 characters.

Now you compare p and x. That fails. There's no x in
the substring, so compare p and f. That fails. Now, f
is the second character in the substring. So move the
possible end point forward by the length of the substring
minus 2.

Now compare p and p, then all the way backwards for
a match.

Modifications of BM do things like instead of picking
the last character, picking a character that is weighted
according to how far along the substring it is and how
infrequently it occurs in the large string.


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




Re: (MORE INFO) loose matching with regex

2001-07-28 Thread Me

 search for 'efghmnop'
 in 'abcdefghijklmnopqrstuvwxyzabcdefghmnop'
 
 Take the last letter of the searched for substring, p.
 
 Pick a possible substring endpoint in the large string.
 This starts out at an offset from the beginning of the
 large string. The offset is the length of the substring.
 
 So, in the above case, you start by comparing p and h.
 
 That fails. Next, given that there is no l in the substring,

Oops. I'll leave working out the paragraph I accidentally
deleted as an exercise to readers...


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




Re: deleting lines

2001-07-27 Thread Me

 I would like too delete the 2nd, 3rd, 4, and 5 lines of a file.
 how can i do ?

Try this at a shell prompt:

perl -ni.bak -e '$. =~ /[2-5]/ or print' FILENAME



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




Re: Passing a class to subs

2001-07-05 Thread Me

First:

Can't modify subroutine entry in character translation at
...ESEC_VALIDATE.pm line 31, near tr /[a-z]/[A-Z]/;

The matching line is:

$q-params('company') =~ tr/[a-z]/[A-Z]/;

This line attempts to change the thing on the left hand side,
and perl doesn't see the thing on the left hand side as
modifiable.

Now, if instead you did:

$c = $q-params('company');
$c =~ tr/[a-z]/[A-Z]/;

perl will be happy. Presumably you would follow this with:

$q-params('company', $c);

to write the new value back to the 'company' field.

Perl has tricks that let some subs be lvaluable (able to be on
the left side of a modifying statement), eg:

substr($c, 0, 5) = 'foo';

but most subs are NOT yet lvaluable, even if that would be natural,
as it would in the case you have here.

--

Second:

syntax error at ESEC_VALIDATE.pm line 32, near );

The matching line is:

$q-params('company') = substr($q-params('company',0,30);

which is missing a closing parens. (It also looks like it's got other,
non-syntax, errors in it.)

--

hth




Re: Match range of array elements?

2001-07-05 Thread Me

I don't know why the shorter version isn't working for you.
I know the basic code fragment itself is fine.

I notice that your shorter version has four dashes rather
than the five in the longer version. Is that it? Other than that,
I suggest you use the debugger or just pile in prints to see
what's going on.




Re: RE:regular expression

2001-07-05 Thread Me

 Hi, I have the following string into a file:

 LOG_INFO : cpcdos23.col.bsf.alcatel.fr: read request for
/bootp/popo.txt:
 success.

 And I have this code:

 my ($f)=@_;
 $thistime=(stat($f))[9];
 return if ($thistime == $mtime);

 $mtime=$thistime;
 my $dummy;
 open (FILE, $f) || warn Couldn't open file $f: $!;
 @lines=FILE;
 close (FILE);
 ($dummy, $IP_address, $read, $status)=split(:,$lines[$#lines-2]);
 $IP_address=~s/^\s*(.*)\s*$/$1/;
 ($client_name)=split(/\./,$IP_address);
 $read=~/.*bootp(.*)\s*/;
 $boot_file=$1;
 $install_file_path=~/\/(.+):/;


 It works fine but only ythe last line doesn't work in fact i want to
display
 /bootp/popo.txt.


 $install_file_path=~/\/(.+):/;

First, I'm pretty sure you expect this statement to set
$install_file_path to something, but the reverse is true;
the thing on the left of the =~ operator is assumed to be
the string being searched. If the thing to the left is not
defined, the statement does nothing. I'd assume you
want $read in place of $install_file_path.

Second, there's a : in your regex, but there can't be any
:s in the string that's been split up, because : is the
character on which the original string was split, and the
character on which the string is split is thrown away
(unless you tell split to do otherwise).

Try:

$read=~/.*(\/bootp.*)\s*/;
$install_file_path=$1;





Re: Match range of array elements?

2001-07-04 Thread Me

if ($printLine[$state..3] =~ /^/)

1. The syntax $foo[] signifies a single element of array @foo.
The . bit is in scalar context and should evaluate to a *single*
*numeric* value. Hence the complaint:

Argument  isn't numeric in array element


2. When you use a variable that isn't defined, and you have
warnings switched on, perl will complain. For some lines of
your TEST file, $state ends up not defined, hence:

Use of uninitialized value in pattern match (m//)

The line number for the specific lines is given in the error message.


To make matters worse:

3. When you use the X..Y syntax in a scalar context, the ..
operator is the bistable (flipflop) operator, not the range
operator.

4. The =~ operator expects a single value on the left side.


You clearly ain't doing what you want to do.

I don't know what happens earlier in your script (and given
the errors above, I ain't too confident you've gotten it right),
but to match against a range of array elements, how you
might want to try:

if (grep { /^---/ } @printLine[$state..3]) {;

to match any, or

if ($state..3 == grep { /^---/ } @printLine[$state..3]) {;

to match all. You should add an assert that $state is (or
evaluates to) an integer between 0 and 3. And both of
these are somewhat obfuscated coding. Perhaps:

# to match any
my $match = 0;
for ($state..3) {
$match ||= $printLine[$_] =~ /^---/
}
if ($match) {

or

# to match all
my $match = 1;
for ($state..3) {
$match = $printLine[$_] =~ /^---/
}
if ($match) {

would be better, though note that the latter indicates
you have matched all if $state isn't in the range 0-3.

hth.




Re: How is this doing what I want it too?

2001-06-30 Thread Me

[note: for some reason, your perl script came through
(at least on my email client) as an attachment. if you
can stop that happening, that would be nice.]

-

 for ($i=0; $b[$i] != undef; $i++)

!= is a numeric comparison.

Line 1544 of list is:

#stopped at 867

and in perl's book, that isn't a number.


 for ( $i = 0; !!$b[$i] ; $i++)

! alone, is a generic 'not'. It is neither a numeric nor
a string operator.

!! is redundant. It means 'not not'. You can just leave it out:

for ($i=0; $b[$i]; $i++)

In general:

1. If you just want an obvious is this thing set?, just
say things like:

if ($foo)

2. Don't do comparisons with undef. If you really need
to test the definedness of something (not something
you really need to do much as a beginner), say
something like:

if (defined $foo)




Re: Inheritance of package global variables

2001-06-29 Thread Me

 [inherited attributes]
 [get/set accessor methods]
 [regex validation of set]
 [better way?]

I'm not sure about there being a *better* way,
but I'm sure there are a lot of *other* ways.

Various thoughts...

Perl has the concept of tied data items. The basic
operations on those data items, like setting the
value, are done via arbitrary procedures you write.
I can see one implementing what you describe, as
a tied hash. To see a little more of what people
have done with tie's in general:
http://search.cpan.org/search?mode=modulequery=tie

Of course, there may be other tied hash implementations
not on cpan.

If you don't have Damian Conway's book, get it.

You might be interested in considering how CLOS
(common lisp object system) notions relate to what
you are doing. With CLOS, firing a method (which
could be an Accessor method), meant the method
dispatcher first looked to see if any Before methods
matched the argument signature. If so, it fired the
matching Before method(s). Those Before methods
could then modify the dispatch process, eg abort the
dispatch. At least, this is how it worked when I last
looked at CLOS, about 10 years ago.

This is a very general framework with what you are
doing being one of many things that are naturally
expressed using it. You could have a Before method
that validates the argument to an Accessor method 
against a regex, and accepts/aborts the dispatch. 
But to get this to work with Perl, you'd have to play
with the guts of method dispatch, something I would
guess is a relatively non-trivial undertaking.




Re: Problem with hash value

2001-06-29 Thread Me

  sub card{
 
my %card_map;
my ($num)=@_;
   @card_map{1..9}= qw(one two three four five six seven eight nine);

 You are putting the numbers 0..9 in the array @card_map here, not in
the
 hash %cardmap.

No he isn't. (He's using a hash slice, which is fine.)

I would think you are always getting 'one', right?

That's because:

my ($num) = @_;

puts the length of @_ in $num.

You want:

my ($num) = shift;

or

my ($num) = @_[0];

hth.




Re: Problem with hash value

2001-06-29 Thread Me

  I would think you are always getting 'one', right?
  
  That's because:
  
  my ($num) = @_;
  
  puts the length of @_ in $num.

Sorry, I'm being an idiot. You were doing the right thing.

 $ more number
 3
 5
 $test10.pl  number
 ``rd 
 bard

Hmm.

  print card  of $_ is: card($_), \n;

Ah, this looks suspect. No operator between
the first string and the sub call.

This is your problem. Play with this and let us know
what's going on:

perl -e 'sub f { foo }; print bar f'

Gotta run...




Re: Clear screen

2001-06-28 Thread Me

I used this instruction to clear the screen on NT

system(cls);
print Hello;

   the same instruction is not working on unix. I modified the
instruction to

   system(clear);
   print hello;

 This works fine on unix. Is there any instruction in perl to perfom
clear screen and it works on both windows and Unix

 Thanks in advance,

Would this:

clear;

assuming an earlier:

sub clear { system($^O =~ 'win' ? 'clear':'clr') }

be ok?

A more general solution for this sort of problem
(portable standard utilities) is to use Perl Power Tools:

http://language.perl.com/ppt/

but they haven't (yet?) been nicely bundled on cpan.




Re: Content-type

2001-06-28 Thread Me

 Im using Content-Type TEXT/PLAIN charset=US-ASCII

I think you're missing a colon, and you possibly
have other syntax errors. Check on the net for
the syntax of the Content-type line.




Re: Windows Background Process

2001-06-27 Thread Me

 I need to start an external program from my perl
 script.  This program will need to run in the
 background so my script can continue doing other
 things.  It also still needs to notify the program
 when it terminates.
 
 I would appreciate any help on how I would do this. 
 My environment is Windows NT 4.0, with Activestate
 perl 5.6.1.  I'm also not sure how Windows runs a
 background process, so any tips there would be
 appreciated.

No one else has attempted to answer this (too busy
having fun out obfuscating each other ;), so even
though I'm not well qualified to answer, I'll have a go.

Basically, afaik, windows doesn't have a native way
of doing this at the OS level, at least afaik. But all is
not lost; read on.

On unix like OSes, the main piece relevant to this
is called a 'fork'. In  a nutshell, a given process has
a child, resulting in the original process (parent) and
the child.

Perl has a high level function, also called 'fork', that
makes use of this. It uses native forking capabilities
on unix like OSes, and emulations on some other
OSes, and simply isn't available on yet other OSes.
With perl 5.6, on some versions of Windows, a fork
emulation has been written. It is likely to be quite
slow, but it may well be usable. So, try that.

For more info:

perldoc -f fork

Apparently, a module called Win32::Process is also
available for this sort of thing and may be a lot faster.

hth.




Re: FW: rmdir

2001-06-27 Thread Me

 PC  chdir /u131/tmp or die $!;
 PC  opendir(HERE, '.');
 PC  @AllFiles = readdir(HERE);
 PC  foreach $Name (@AllFiles) {
 PCif (-f $Name) {next}
 PCif ((-d $Name) and ($Name =~ /^[A-Z]+$/)) {rmdir $Name}
 PCif ((-d $Name)) {print $Name\n}
 PC}  

 It's working great.  Thank you.  But one more thing,
 it's removing all the empty directories but what about
 directories with files in them.  It errors out when it hits
 a directory with files in it.  I have just files in this directory
 that I don't want to delete.  I only want to delete the
 directories with Capital letters and the files in them.
 Thank you for any help or ideas.

You have to go to another level of programming,
and use recursion. You may find this easy or it
may wrap your brain in knots, it depends on the
person.

Basically, you have to write a sub that does the
following sort of thing (ignoring your wrinkle that
you don't want to delete all the files in the initial
directory):

emptyoutdir
foreach direntry
file: delete it
dir:
cd direntry
emptyoutdir
cd ..
rm direntry

Writing that is easy once you understand that
whatever variable you use to contain the current
direntry needs to be local to its own level of call;
otherwise, the 'rm direntry' is going to be acting
on the 'direntry' value last set by the emptyoutdir
called just before it (or the emptyoutdir that that
called, or... and so on, down the depths of stacked
emptyoutdir calls).

Go on, have a go, then post your best shot.

Initially, just try to print the files/dirs, don't try to
delete them. Remember, you are playing with
fire here; something that will delete entire trees
of files/dirs, and anyway, you don't want to keep
deleting your test dir structure. To make it a bit
easier to see what's going on, add an indent
variable in to the sub like so:

emptyoutdir
my indent = indent;
indent++;
foreach direntry
file: print   x indent . file
dir:
cd direntry
emptyoutdir
cd ..
print   x indent . direntry

have fun...




Re: Wanted: Explanation of array slices used in hash creation

2001-06-27 Thread Me

@$hashref{@array};

One thing I remember finding useful in understanding
this sort of stuff is that the sigils (@, $, etc.) are more
binding (have a higher precedence, as it were), than
subscript parens. So you deal with them first.

So @ followed by other sigils is going to end up with
a bunch of dererences, and then be equivalent to @
not followed by other sigils. Then you are left with:

@arraylikething{@anotherarraylikething}

the combination of @foo{@bar} (or where @bar is
just a list), is always a hash slice. And a hash slice
is simply more than one key being considered at
the same time, so it's just the multiple version of:

$hash{foo}

hth.




Re: subroutine as search string?

2001-06-27 Thread Me

s/// and friends first parse their contents as double
quoted strings, before ever considering the content
as a regex.

So you can do:

$foo = '[a-';
$bar = 'z]';

s/$foo$bar//gi;

and it will work (stripping letters).

Furthermore, you don't need any dynamic behavior
for the search part of the s///, so it's fair to view it as
just a string, with subs being used to make a var
that contains the string.

Enough preamble.

One way is to keep your sub, but use it this way:

$search = 
standard_search(Call Log) .
standard_search(Billing Log) .
standard_search(My Account) .
standard_search(Help) .
standard_search(Calling Plans);

s{ $search } { $3 $1 $2 $5 $4 }gx;

hth.




Re: substr (help,help,help);

2001-06-27 Thread Me

 while (SOURCE){
  if (m/\/nic\/login/){

this just says yes or no, you have a match or you don't.
m// (and friends like s///) can do more than that for you.
for one thing, they can grab a particular piece of what
they match.

  substr ($_,28,4);

what substr normally does -- get or change a piece of
a string -- overlaps what m// and friends can do. if you
are already using m// or friend it's often simpler to use
that to do what substr can do.

in the above case, substr isn't doing anything at all!
you don't set that part of the string to anything, nor do
you set any variable to contain the bit that's grabbed.
you're simply saying, grab a copy of that part of the
string, then throw it in to the great big bit void in the
sky. you could do:

$foo = substr($_, 28, 4);

but, as noted above, it's easier to extend your use of m//.

btw, why did you say 4, not 5? 'Login' has 5 characters
last time I looked!

back to m//. Try this:

($mybit) = m#/nic/login/([^]*?)#;

I used # as the m delimiters so you don't have
to escape the / characters.

the (...) is the bit that grabs something.

the [^] bit means match anything but a  character.
the * bit means match any number of non 's.
the ? bit means match as few as still makes the
match true (if possible). (otherwise the grabbed bit
would be the rest of the line up to just before the last 
encountered.




Re: How can I set return codes for a perl-script?

2001-06-27 Thread Me

 I want a perl-script to be startet by another application. Is there a
 possibility to send a return code from the perl-script to the
application
 saying whether the perl-script was running properly? Is this working
for
 Unix and NT?

use exit, eg

exit 2;




Re: Variable scope

2001-06-26 Thread Me

  I could not get the following sub to work until 
  I had to move  $emailLog inside the sub to get this 
  to work on the server. 
  
  What did I miss or not understand?

More on that in a moment. First...

 Try putting a my (without quotes) before the variable.
 What that will do is to make it global

I think I see where Geraint is coming from, but a my'd
variable is the only type of variable that is NOT a global,
using the term as it is used in official perl documentation.

As to your problem, was the sub called from another
perl file? If so, and it used a different package name,
then that would explain the problem. Let me know if
this was the case, and we can go on from there.




Re: Variable scoop

2001-06-26 Thread Me

 I don't know why it was not working earlier 
 when emailLog = 'logs/email_log';
 was out of the sub block. 

Did you use a 'package' command anywhere?




Re: use of $_

2001-06-26 Thread Me

 What actually sets the default variable?

All sorts. Totally ad hoc.

Be prepared to check and learn what does
or doesn't set and use it, or realize that it
can be changed on you by something else.

When you know what you are doing, you may
find localizing $_ useful, but it would be remiss
of me to tell you more just now.




Re: Debugging the CGI - Application

2001-06-26 Thread Me

 I am facing was difficulty in debugging the script in my CGI base
 application.

 To get the feel of the program I use print statements where ever
possible.
 But causes problem with setting cookies as this header has to be
written
 before any thing with can be display as html.

 I would be greatfull if any one can give me better solutions for this.

Perhaps CGI::Carp.

use CGI::Carp qw(warningsToBrowser);

carp Boohoo;

warningsToBrowser(1);

http://search.cpan.org/




Re: Debugging the CGI - Application

2001-06-26 Thread Me

 Any more suggestion ?

If you are allowed to modify your web server's setup, then:

http://www.masonhq.com/docs/manual/Mason.html

and prepare for your world to be turned upside down...




Re: compiled/interpreted??

2001-06-26 Thread Me

 [is perl compiled or interpreted?]

yes.

 Can anyone explain this in detail???

chapter 18 of 3rd edition of Programming Perl.




Re: Help please (any one)

2001-06-25 Thread Me

 1. If we are after field 15, how comes you used field 14 in your
 answer please!   *if ($fields[14] =~
/M/)***

The Nth element of an array is offset N-1.

So $foo[0] is the first element, $foo[1] is the second
and so on. This is a common practice in computing
languages.

 2. Were could I read up on 'regexp' please!

At a shell prompt or command line:

perldoc perlre

More generally:

http://learn.perl.org/




Re: to copy a file (with perl)

2001-06-25 Thread Me

 Hw could I copy a file in Perl

use File::Copy;

copy($file1, $file2);







Re: Exceptions ( catching and handeling).

2001-06-25 Thread Me

 On Mon, Jun 25, 2001 at 12:12:19AM -0500, Me wrote:
   $done=false;
   
   while( $done eq false ) {
   eval {
   ..
   .
   read form files.
   process info...
   write back to files
   
   };
   ( $@ ) ? ($done=false) : ($done=true);
   
   }
  
  I don't understand why this isn't working. Change the $@ line to:
 
 The test is ( $done eq false ) - note the space after false.  That
 will never match.

An eagle eye indeed!




Re: removing ASCII characters from array

2001-06-25 Thread Me

 But that wasnt the question man =)
 you print '230107312001,32,192,239'
 
 but the question was to just have: '32,192,239'
 
 -10 cookie points! ;-)

Oops, being careless.

You could throw away .*?= first:

$_ = Sat Jun 23 01:07:31 2001,bytes=32,time=192ms,TTL=239;
s/.*?=//g;# remove leading junk
s/[^\d,]//g;# remove all but digits and commas
print;

Can I get a cookie point or two back? Please? ;

Otoh, I think the original suggestions are neater.
So I guess I'll have to get points on some other answers. ;




Re: removing ASCII characters from array

2001-06-25 Thread Me

 s/.*?=//g;# remove leading junk

should of course be

 s/.*?=//;# remove leading junk

Ok, ok, I accept another -10 points. : ;




Re: Regexp question

2001-06-25 Thread Me

 [matching web page links]
 [using regexes]

Don't use regexes. They aren't the right tools for the task.

Use one of the cpan modules for parsing web pages.
Some are written specifically for pulling out links.

http://search.cpan.org/




Re: Regexp question

2001-06-25 Thread Me

 Drats - just when I got the regexp worked out too...
  $_=~ m/(A)(.*?)( \/A)/

Kudos for working out the regex that works given your
assumptions. If the web pages you will be parsing are
known to be constrained to the assumptions you've
established, then you're done.

But be aware that your regex will fail on some web pages.
And tightening up the regex to cope with the exceptions
rapidly becomes a futile exercise. Experienced perl
coders don't use regexes for most recursive and most
hierarchical parsing tasks, such as parsing html or xml.

This has been discussed an infinite number of times on
many perl lists for several years. Some recent experimental
regex extensions begin to break down this barrier to use of
regexes for recursive and hierarchical formats, but they are
still very much experimental, and are still pointless in the
particular cases of html and xml given the available cpan
modules.

But, as always, timtowtdi...

   [matching web page links]
   [using regexes]
 
  Don't use regexes. They aren't the right tools for the task.
 
  Use one of the cpan modules for parsing web pages.
  Some are written specifically for pulling out links.
 
  http://search.cpan.org/




Re: Re: Failed in package programme, how do I use package and object?

2001-06-24 Thread Me

[everyone, please keep posts on list]

 I'm programming a registration  editing produce for my site,
 I want to bind many of same subroutine into a library, and reuse
 these routines in same case.

You don't need to use objects at all. You can just use the package
and module concepts. You can ignore bless and instead of doing

use Baz;
$qux = Baz-new;
$qux-foo;

you can do:

use Baz;
Baz::foo;

or

use Baz;
.
.
package Baz;
foo;

 I had tried your suggestion, here are several confuse point:
 First, for replacing my line:
   print $c-displaysub().$a;
 you give me:
   print $c-displaysub().$ct::a;
 What is $ct? I'm afraid that it is an err in keyboard.

Oops, I meant pt. $pt::a means $a in package pt.

 And when I use the following line in pt.pm
   our $a;
 system send me a terminated message,my system is Win98+Apache1.3.6 for
win32+perl5 for win32. Perhaps it doesn't support 'our' declaration?

Oops, how quickly I've forgotten pre 5.6.

Use:

use vars qw($a);

 Additionally, I'm unclearly in bless function  $self={},
 by perl's manual, bless as an inheriate declaration, by your
 explain, $self={} is for defining a group variables what
 inheriated from parents class, isn't it?

bless has got nothing to do with inheritance.

Clear your mind of whatever you have read or thought.

bless does one simple thing. It associates a reference
with a package. That's it.

In appropriate circumstances, eg:

$foo-bar;

perl looks to see if a reference is blessed, and if so,
retrieves its associated package and acts accordingly.
(In the above case is starts by looking for a bar sub in
that package, and if it finds it, it calls it.)

-

$self is just a convention that a) you name the reference
about to be blessed (it doesn't need to be) and b) you
use $self as the variable name. You don't have to name
the reference. You do want to name it, you can call it
$charlie.

-

Using {} or [] as the reference rather than \$foo is really
nothing to do with objects either, though, again, it is a
natural for this role.

Consider:

$x= [];
$y = [];
$x-[0] = 'red';
$x-[1] = 10;
$y-[0] = 'blue';
$y-[1] = 20;

Here, the variables have nothing to do with objects.
They are just array references. (Actually, I'm making
an assumption here. Are you familiar with references?
If not, the rest of this probably won't make sense.)
When I dereference the variables, I can store values
in their respective arrays. Nothing unusual here, right?

I can do the same with hashes of course:

$x= {};
$x-{color} = 'red';

Again, nothing to do with objects, and simple enough, right?

Now let's create an object from a reference and then use
that object:

$qux = bless \$foo;

$qux-foo;

If there was a foo subroutine defined within the current
package, then the last line will work.

(As you can see, even the sub we used before is not
strictly necessary, just the bless.)

Now, we can call any sub defined within the package
into which $qux was blessed:

$qux-bar;
$qux-baz;
$qux-waldo;

but what if we want to store some instance data with
the $qux object, like its color? Hmm. Where to put it.

Hmm. What if we did:

$qux = bless [];

instead of bless \$qux.

Ah, that's better, we can now say:

$qux-[0] = 'red';

Bingo, instance data! We could also do:

$qux = bless {};

$qux-{color} = 'red';

And that would work too.

Now, imagine that this package inherits from anotherpackage,
which in turn inherits from yetanotherpackage. Let's say, when
you wrote your code, yetanotherpackage already had uses for
[0] thru [2], and [3] was used by anotherpackage. Now you add
your package and you start using [4] thru [6]. Later on, the
author of anotherpackage decides to make use of [4]. Argh.
Ok, s/he could speak to you and agree to use [7] instead, but
then they find out that one of the many other authors that have
written code that inherits from anotherpackage has used [7]
through [10]. Basically, it's a mess.

Using hashes is a much better solution than arrays. It does
not completely eliminate the instance data indexing/naming
clash problem, but it makes it manageable.

hth




Re: Help for a newbie..

2001-06-24 Thread Me

 im a newbie to PERL.. right now, im learning it but i dont have any
exercises
 to work on. i need them because its how i learn.. can please someone
tell me
 what is a nice thing to do when you are still starting to learn PERL
and you
 want to enhance your skill
 tnx

http://learn.perl.org




Re: Filehandles

2001-06-23 Thread Me

 I want STDOUT to be sent to a FILESHANDLE. I have a script writing
output
 DISPLAY..But I wanna this to be going into a file through FILEHANDLES
..

 Ur Help is Highly APPRECIATED

Well I'll SEE if I can HELP YOU.

open(STDOUT, foo) or die can't redirect STDOUT: $!;

HOPE THIS HELPS.

(Please don't use allcaps so liberally. It is like SHOUTING
for no good reason, and it's quite distracting to many readers.)




Re: Failed in package programme, how do I use package and object?

2001-06-23 Thread Me

 I'm try my best

And you had 99% of it right.

 package pt;
 use 5.;
 $a=ok;  #for public using
 $b=It's;
 
 # I don't know why put the newsubroutine in this package,
 # perhaps, it is a constructer, I copy from PERL's manual,
 # but it seem don't do anything.

Most of what you wrote is redundant in this
particular case. You could have written:

package foo;
sub bar { bless \$qux };
.
.
package waldo;
$emerson = foo-new;

As you can see, $emerson is just a reference to $qux.
And $qux is undefined, but has one special property:
it's been blessed, which is how you turn a reference
into an object (which is just a reference that knows
what package it belongs to). Simple, really.

As you start to do more complex things, your constructor
needs to get a bit more clever.

In particular, what if the following call appears:

oof-new;

and oof ISA (inherits from) foo, and has no constructor
defined, hence inheriting its constructor from foo?

Well, bless with one argument (as used in my snippet
above) associates that argument with the current
package, in the above case, foo, thus constructing a
foo object not an oof object. So one needs to find out
what package name was used to call the constructor
(the package name is conveniently passed as the
first argument whenever a sub is called using the
object oriented syntax) and then use the two argument
form of bless:

 sub new { 
 my $type = shift;
 my $self = {};
 bless $self,$type;
 }

The $self = {} bit is so that the object can carry around
data as well as being blessed (which, applied to a mere
scalar, means you can only access subs (methods)).

 package main;   # My application
 use pt
 $c=pt-new();
 print $c-displaysub().$a;

The $a is assumed to be in the main package.

Use either:

print $c-displaysub().$ct::a;

or use our:

package pt;
our $a;
package main;
print $c-displaysub().$ct::a;

or create displaya, an equivalent of displaysub,
only for $a, and call it as a class sub:

package pt;
our $a;
package main;
print $c-displaysub().ct-displaya;

hth




Re: Failed in package programme, how do I use package and object?

2001-06-23 Thread Me

Good job I decided to write this as two posts.

 Most of what you wrote is redundant in this
 particular case. You could have written:

(I was just refering to the constructor, btw.)

 package foo;
 sub bar { bless \$qux };
 .
 .
 package waldo;
 $emerson = foo-new;

That should of course have been:

 $emerson = foo-bar;

Or you could have been conventional, and called the sub new,
which is what the next part of my email assumed.

 The $self = {} bit 

The use of $self is again just convention. You could have
written:

sub new { 
my $type = shift;
bless {},$type;
}

or

sub new { 
bless {},shift;
}

or, if you don't want to be able to store instance data:

sub new { 
bless \$foo,shift;
}

Now for the reason I was really going to send this second
post. The mistake you made would have been pointed out
to you (albeit in greek), if you had used:

use strict;

You should get in to the habit of writing this. It would have
forced you to also use my for $a etc, but that's ok. And
while I'm about it, you should also switch on warnings by
using the -w switch:

#!/usr/bin/perl -w

You should burn these two in to your brain. Using -w and
strict will give you a couple extra problems when you first
start using them, but thereafter they will save you a lot of
headaches.




Re: Format Reports

2001-06-22 Thread Me

 Hi
 Is there a module out there that will help me
 format data coming from an Access Database.
 Win32::OLE looks a bit daunting though I'm
 sure it will allow the typographic variety I'm
 looking for.

That's too vague.

Basically, please explain your constraints.

If there are none, then it gets a lot easier.
First, my assumptions, based what you wrote:

1.You have some data in Access running on Windows.
2.The part you are interested in is text.
3.You need to get it out to be processed by perl.
4.You want to inject some formatting using perl.

Second, my suggested approach:

A. Dump the text out as ascii.
B. Run a formatting program over the data.

Yes, this implies no perl.

Are there some constraints that make this
inappropriate, or is one of my assumptions
wrong?




Re: LWP modules

2001-06-22 Thread Me

 there are some forms which execute a 
 javascript on their SUBMIT button and
 the on executing them from my script 
 it gives me an error that javascript is
 not supported like http, ftp or other
 protocols.

Is the word javascript anywhere in your perl script?
Do you mean the action= parameter in the opening
form ... tag starts with javascript:// or similar?
Do you mean there is an onclick or similar part of
the input type=submit ... tag? Or something else? 

 how do I pass parameters to notigy a CGI script
 which is called on submittion of the form to submit
 it and generate the results.

You can probably quickly get this working as a single URL
without using perl, THEN code that URL into your perl.

Basically, you need an URL of the form:

foo?arg1=val1arg2=val2...

where foo is something like:

http://www.domain.com/cgi-bin/qux.cgi

and val1, val2 etc are URL encoded, which means
some characters are converted (eg space = %20).

If you are lucky, the form will do this for you. Try clicking
submit with some data. Does the URL change to an URL
of the form I just described? If so, that's probably the
URL you want.

If not, save the form to you local hard drive. Change the
method= part of the form... tag from method=post to
method=get. Save the edited form, view it in a browser
and submit the form. Do you get the URL you need?

If you do, now go ahead and deconstruct that URL into
the bits appropriate for the LWP user agent. (Or just
use the URL directly if you want, and parse out the
results some other way.)

If not, then you are going to have to get your particular
target form submission working using LWP user agent
modules without the benefit of first getting a plain URL
working. But, in that case, you should first get things
working for some web form that DOES allow method=
get, just so you go through the steps above and get the
hang of determining what is an arg to a cgi, and how
you can specify that using an LWP user agent. This
will involve looking inside the html to find input... tags
and similar. Once you have it working on that other web
form, then go ahead and attempt to get your original
target form working.

hth.




Re: HTTP::Status status_message($rc) LWP::Simple

2001-06-22 Thread Me

Do you mean use the result from such a call,
or how to do such a call? I'm guessing doing
the call, and a somewhat wild guess is:

HTTP::Status::status_message($rc)

Assuming $rc has been set to something

You may need to do a:

use HTTP::Status;

or similar, before you make the call.

And that might mean you need to install the
HTTP::Status module.

Otoh, I've never used HTTP::Status...

hth.

 How would I adapt the else print statement to use
 HTTP::Status status_message($rc)?
 
 TIA
 
 drew
 -- snip --
 use LWP::Simple;
 
 while (){
 if (get $_) {
 # url is ok
 print;
 } else {
 # couldn't get url
 print \nAn error occured with $_\n;
 }
 }





Re: GDBM_File

2001-06-22 Thread Me

 use GDBM_File; works OK

what did your tie statement look like?




tutorial on my/our/use/package/local

2001-06-21 Thread Me

There's plenty of existing doc, but in the name of TMTOWTDI...

Asbestos suit donned. Criticisms welcome.

--

If you are wondering about things like:

use strict;
my $foo;
our $bar;
local $baz;
explicit package

then this article might be of help.

--

Before we can understand a noun, like Paris, or a verb,
like move, we need to understand the context. Does
Paris refer to the town in Texas, USA, or the city in France?

A perl script is aware of multiple namespaces and the
meaning of a word is often established by associating
it with one or other of these namespaces.

One important job you have in coding anything but the
simplest perl script is to let perl know which namespaces
should be available and which namespace should be
used for context when you use a given word.

--

In perl, namespaces are called packages.

Every perl script automatically knows of two packages,
main and MY*.

--

Unless you declare a name as being in some other
package, a name is assumed to be in the main package:

$_ = 1;

# $_ is in main.

--

In general, you should not be lazy and let your names
fall in to the default main package. Instead, you should
declare variables you create as being in MY package:

my $foo = 1;

foreach my $element (@array) {

Unless you are writing a perl one liner, make sure you
declare your variables with my. Don't be lazy or you will
get in to trouble later...

--

Beyond main and MY, the other packages you are
most likely to use are packages written by others.

Before we look at the syntax involved, a brief digression
as a motivation for learning this package stuff:

Amazingly, a huge number of high quality packages
are available publically for free in one nice big catalog
called CPAN. Some come with perl as standard.
Others need to be pulled in from the Internet. You can
browse and search CPAN using a web browser:

http://search.cpan.org/

More on this in a footnote**.

--

Apart from main and MY, all other packages have to be
given a name.

In a similar fashion to use of / (or \) in directory names
on hard drives, package names often include '::' to
separate logical levels of the package name. For
example, one package on CPAN is:

File::Copy

--

To use another package written by someone else,
you write something like:

use File::Copy;

this makes the File::Copy namespace available.
So you can write things like:

use File::Copy;

# Invoke File::Copy's move() procedure:
File::Copy::move(file1, file2);

This is very explicit. There is no room for ambiguity.

But it sure is long.

Fortunately, the 'use File::Copy' statement does more
than make the namespace available. It also imports
some names right in to your main package. So you
could write:

use File::Copy;

# Invoke File::Copy's move() procedure:
move(file1, file2);

Which names get imported in to your main package
depends on a combination of what the author of the
package decides, and what options you specify
when you use the module. For example, you can say:

use File::Copy ();

and File::Copy won't import any names in to main.

--

If you are writing more than a one liner, you should
start your scripts with:

#!/usr/bin/perl
use warnings;
use strict;

Once this is done, if you don't say where a name is
from, perl will complain that you have not provided
an explicit package name. This is a good thing, as
it forces you to be careful, and this particular form
of care will save you countless hours of frustration.

As already stated, most of the names you come up
with will refer to things that are, well, yours, so you
typically write things like:

my $foo;

so that $foo now belongs in the MY package.

If you want to refer to something from another
package, you can either specify the longhand:

$Foo::bar = 1;   # set $bar from package Foo.

or introduce a shorthand version of the name
like so:

package Foo;
our $bar = 1;   # set $bar from package Foo.
our $baz = 2;   # set $baz from package Foo.

$_, @_, STDIN and other standard Perl variables
are exempt from 'use strict' complaints. Indeed,
you can't my these variables even if you wanted to.

--

If a my or our declaration is inside braces, Perl loses
all memory of that declaration when it encounters the
enclosing end brace:

#!/usr/bin/perl;

my $foo;
{
my $bar;
# MY namespace contains the names $foo and $bar.
}
# MY namespace no longer contains the name $bar.

--

My/our declarations stack variables on top of each other
(and unstack too) and hide other variables with the
same name:

#!/usr/bin/perl;

$foo = 1; $bar = 1;
# main package now contains a $foo and a $bar.

my $foo = 2;
# MY package now contains a $foo.

print $foo;
# Refers to MY foo in preference to 

Re: Re:MANPAGE

2001-06-21 Thread Me

 How do I get access to the manpages please

Depends on the system, and you may not be
able to get access.

One normal access method is to enter, at a shell
prompt (command line):

man foo

to access the man page for foo.

Perl has its own equivalent of manpages. To start,
enter at a shell prompt:

perldoc perl

hth




Re: PROGRAM!

2001-06-21 Thread Me

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

means you can't just go introducing names
willy nilly without telling perl where they come
from.

which in turn means...

 while () {
 
 @fields = split /*/;

you can't do this!. oops. should be

  my @fields = split /*/;

 for (my $i = -1; $i  -9; --$i) {
 
 print $fields[$i] . \n;
 
 }
 
 }

 Q IS this what you want me to change it to

 for (my $i = 0; $i  -3; $i  -7) {

Nope. This form of a for loop works like this:

for (start; test; change) {

do something

}

where 'start' tells perl the starting arrangement,
'test' is something perl tests each time it is at
the top of the loop, and 'change' is something
perl will do each time it reaches the bottom of
the loop. The 'change' bit had better change
something otherwise the loop will just go on
repeatedly doing the same thing.

So, the $i  -7 bit doesn't make sense because
it isn't going to change anything.

The loop I had written was going to start at index
position -1, which means the last element of an
array, then step backwards through the next 7
previous elements. I thought that was the address.

You need something more like:

print $fields[0] . \n;
print $fields[3] . \n;
for (my $i = -3; $i  -7; --$i) {
print $fields[$i] . \n;
}

 PS. not able to get access to the manpage.

That's like saying, you still can't get access to the software.

What manpage? On what operating system?




Re: file size

2001-06-21 Thread Me

-s

as in:

perl -e 'print $_:  . -s . \n for (glob (*.*))'

 Hi,

 I would like to know if with a perl script you can get the size of a
file ?
 I need to get all the size of 250 files on 250 computers ...

 thanx




Re: RTF to HTML or text conversion

2001-06-21 Thread Me

http://search.cpan.org/

 Im trying to write a perl script that will pull newspaper stories out
of a
 sybase database and post them on the web. I can connect to sybase,
pull
 stories, but they are in Rich Text Format. I would like to convert the
RTF
 to text or html. Could anyone point me in the right direction ?

 Thanks
 jon




Re: use of require causing name space problems?

2001-06-21 Thread Me

Ok, I entirely retract my post to which this is a reply.
Hey, I've been up all night.

If the scripts are running as separate processes,
then, well, I don't know.

 Does anyone know why perl behaves like this?
[see earlier posts in thread]




Re: tutorial on my/our/use/package/local

2001-06-21 Thread Me

 Brutal critique enclosed... beware, I get right to the point. :)

Hmm, I enjoyed it, so I'm thinking I must
be more SM oriented than I thought...


 Me # $_ is in main.

 $_ is always in main, even if the current package is something else.

Yes. I spent some time considering where this was
best revealed, and wrote it in in various places as
I drafted this article along with other stuff such as that
you can't my $_. But these details ultimately bit the
digital dust.


 Me Amazingly, a huge number of high quality packages
 Me are available publically for free in one nice big catalog
 Me called CPAN. Some come with perl as standard.

 That'd be modules, not packages.

My early drafts tried to maintain the module/package
distinction. But on balance, I decided the distinction was
not merited given the kind of material I was trying to write,
especially given that I judged that the lie does little damage.

I found that the sleight of hand of focusing on packages
as against modules, and indeed on the content of a
package (its names) as against the package as a
singular entity, worked better than the alernatives I
came up with.

My intent was to say, you could go get a namespace
(set of names) by going to CPAN, and I thought that
that was a reasonable way of looking at it. Again, one
draft used 'namespace' throughout and deliberately
eschewed the terms module and package.


 Me Apart from main and MY, all other packages have to be
 Me given a name.

 main is a name!  MY is not a package.

main is the name of a namespace.

MY is my name for what is currently (perl 5) an
anonymous namespace. A package is a namespace,
and I felt that less damage was done in this article
if I also used the white lie that a namespace is a package.

I'm having second thoughts of course. Larry didn't use
the term package in connection with MY, he used the
term pseudo class. Indeed he specifically said that
one could use it to import things lexically as well as
packagely, indicating that he did not see MY as a
package, or at least not as a package.

Btw, MY was mentioned in Apocalypse II, which is where I
picked up on it. I have no idea what Damian said about it.


 Me To use another package written by someone else,
 Me you write something like:

 Me use File::Copy;

 module!

Well, unless I'm getting something really screwed up
(always possible :), I'd say both.

You have to use the module, to use the names in its
namespace, which is to say to use the namespace,
which is to say to use the package.

I do think the File::Copy wasn't the best choice to
illustrate some of these points. But I decided it was
good enough.


 Me Fortunately, the 'use File::Copy' statement does more
 Me than make the namespace available. It also imports
 Me some names right in to your main package.

 Actually, the current package.

Argh. Bad mistake. Thanks.


 Me use warnings;

 use warnings makes your program needlessly incompatible with 5.5.
 don't do that unless you're also using other 5.6 features.

A useful reminder. Thanks.


 Me my $foo;

 Me so that $foo now belongs in the MY package.

 $foo is now a lexical, not part of any package, and has a scope and
 persistence related to where it is defined, no longer a global.

Again, I think the device of fuzzing the notion of package
serves a purpose and it seemed to serve it well to me.
The truth is s much more complicated!


 Me package Foo;
 Me our $bar = 1;   # set $bar from package Foo.
 Me our $baz = 2;   # set $baz from package Foo.

 our is 5.6, again needlessly incompatible with 5.5.  use vars
qw($bar)
 is the close equivalent for all.

Oh I don't think needless is fair. I certainly wouldn't
have left our out, it's too neat. But I agree it was wrong
not to mention, in fact highlight, our's newness, as well
as to mention use vars.


 Me If you redeclare a my, you throw away the old value:

 Me my $foo = 1;
 Me my $foo;
 Me # $foo is undefined.

 This is almost certainly unintended, and merits a warning when
 warnings are enabled.

My 5.6.0 does indeed warn.


 Me Only use local if you can't do what you want with my.

 You haven't even mentioned what local is, so it doesn't even suggest
 why you'd want this.

This section barely made my final editor's cut.

I deliberately didn't say how to use it. I mentioned it
enough to say, don't do that, and what you should be
doing instead. Any more seemed inappropriate.
local doesn't have any impact on namespaces or
use of names. It's only to do with values.


 Me * In Perl 5, the package I call MY package is not often
 Me called a package and can't be accessed in the same
 Me way that other packages can be accessed. However,
 Me in Perl 6, there will be a MY package, and, imo, it is
 Me simpler to use the term package for all namespaces.

 This is news to me.

As explained above, I may be technically wrong on MY,
perhaps very wrong. I am not sure how this would impact
how I felt about the package and MY

Re: Can someone help me???

2001-06-21 Thread Me

 @$foo{bar}

What you intend by the above is the scalar value
in $foo{bar} dereferenced as an array by the @.

But that's not what happens. To achieve what you
want, use:

@{$foo{bar}}

The issue here is precedence of sigils (@, $, etc.)
versus subscript parens ({}, []), and the meaning
of various combinations of sigils and subscripts.

Sigils have a higher precedence than subscripts.
To force the meaning you wanted, we, well,
forced the meaning you wanted.

Fwiw, @$foo{bar} specifies that you want a list,
consisting of the values corresponding to the list
of keys in the parens (in this case a list of length
1, namely bar), looked up in the hash referenced
by $foo.

So, this should work:

%h = (key='value', key2='value2');
$foo = \%h;
print @$foo{key, key2};

hth.




Re: FW: PROGRAM!

2001-06-21 Thread Me

 I have made a attachment in word

There really is no good reason to resort to
attachments for this list. As it happens, it
looks like the attachment failed to come
through anyway. Perhaps the list software
rejects attachments.

Anyhow, marking things with stars was fine.

 they are suppose to all be on one line.  However
 I couldn't get the examples on one line for you
 to see, sorry!

Just pick a line-wrap marker, say \\, and type
the example out that way:

The quick brown fox jumped over the lazy\\
 dog. Now is the time for all good men to\\
 come to the aid...

 Question: what would have to be changed,
 so that I only get back only the 3 data items
 that I need please!

I still think the code fragments I posted should
work fine.




Re: trying to convert characters into numbers based on a table

2001-06-20 Thread Me

According to my email client, this just arrived on the list:

From: Cohan, Drew [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, June 16, 2001 2:20 PM
Subject: trying to convert characters into numbers based on a table


It's contents are just slightly different to the one that was also sent
by Drew and which arrived around the time this one was sent:

http://archive.develooper.com/beginners%40perl.org/msg04454.html

I've been seeing a good few double emails recently, with different
timestamps, but this one, two days late, and with slightly different
content, takes the cake...




Re: Extracting data from a web page

2001-06-20 Thread Me

 Randal

Well I'm not Randal, but I'm going to answer anyway...

 Would the same be possible for generating dynamic
 queries of web pages like amazon.

The points Randal made were:

1. Yahoo has URLs that return CSV files.
These are not web pages though the protocol
is http. The perl involved to get the data is not
specific to Yahoo in any way and the data you
get back is in classic CSV form. If Amazon
provide similar CSV links, then you'll be able
to do the same thing with those links.

2. CPAN has modules specifically designed
for Yahoo resources, be they web pages or
CSV feeds. A quick search of CPAN:
http://search.cpan.org/
shows lots of modules for Yahoo, and none
for Amazon.




Re: problem of require

2001-06-20 Thread Me

Stick a:

1;

at the end of the require'd file.

 I got a message when I run the perl script, I never got this msg
before, is
 there anyone can tell me why?
 How can I fix it?
 rplcstr.pl did not return a true value at replacestr.pl line 6

 Tips: on line 6, statement is require(rplcstr.pl);

 Best regards

 Peter Zhou




Re: Recursive subrutines

2001-06-20 Thread Me

 [recursive procedure not localizing array passed as parameter]

 ---
 buildBranch(@someNodes);
 
 sub buildBranch()
 {
 @numNodes = @_;

Use my @numNodes.

my declares a new private variable each time
it is encountered.

Without it, @numNodes is the same variable
each time the procedure gets called, which is
not what you want.




Re: Can you someone help me please

2001-06-20 Thread Me

 Hi All,

 I have been asked to transform this bit of PERL coding into plain
english,
 Can someone help me please.

 Regards,
 Elaine.

Before anyone attempts an answer, are you a programmer?
Do you know what, say, parameters are?


 # Exit code for the ccount form
 sub form_ccount_exit
  {
  if ( $_[0] == 0 )   # exit_RE detected
   {
   if ( $user_input eq $bn_done )
{
$next_form = .. if ( $warehouse eq  );
clear_fields($formname);
}
   elsif ( $user_input eq $bn_main ||
$user_input eq $bn_esc )
{
clear_fields($formname);
$next_form = ..;
}
   elsif ( $user_input eq $bn_logout )
{
reset_to_logout_form;
}
   }
  else
   {
   display_status(Processing...);
   #$err_no = ilc_cycle_counting($order,$warehouse,$location,
   #$item,undef,$lot,$stg_unit,$qty,undef);

   #Get FIFO/LIFO Date from Cycle Count Table

#get_ccorder_item_date($item,$location,$order,$warehouse,$lot);
   $err_no = ilc_cycle_counting($order,$warehouse,$location,
$item,undef,$lot,$cdate,$stg_unit,$qty,undef);
   display_return_msg($err_no);
   }
  }









Re: PERL PROGRAM HELP!

2001-06-20 Thread Me

 Hi, I am new to perl and have been chucked in the deep end!!!   I have
been
 asked to write a perl script, with a output in report style;

 Description for script:
 Read a file,  (sorted)
 take certain data from the file,  (problem)
 put the certain data in to fields.(problem)

 The big problem being that the File is not sorted in any form, e.g. no
 existing columns or fields or Headings!

 What I need to get from the file are:
 ID NUMBER, BranchNAME,
ADDRESS.

 The file contains the above 3 data types and about another 5, which I
need
 to get rid off!

 Can any body please suggest how do this task or what I need to read up
on
 (topics e.g. Report writing etc) or any other tutorials on report
writing
 or, any thing to show me how to get certain data from a file
 please

 Any help would be appreciated as I only have two days to this in!!!

Post an example of the input, 10-20 lines or so.
Also, state roughly how many lines there will be in
an input file.

Reading the file, pulling data out, and structuring
the data you've pulled out, will probably be relatively
easy based on your brief description.

The output might be real simple, or might be tricky,
depending on what's needed.

So, post a better idea of what output is needed.

If the output is going to be pretty short and/or only used
a couple times, it might be best to just keep the output
format extremely simple.

Otherwise, if you can dump the output into some other
software that's good at taking structured data and
doing report layouts of the sort you need, then maybe
use that.

Otherwise, if the output is going to be many pages long,
and you want fairly simple report style pagination and
formatting, then you *might* want to use perl's 'format'
features. To read up on the latter, type the following at
a shell prompt:

perldoc perlform




Re: move folder?

2001-06-20 Thread Me

 Is there a Perl way to move a folder with out doing it one file at a
 time?  (Similar to M$ Windows Explorer where you can drag a folder to
 another folder?)

In some cases:

rename $Old $New;

will work.

In some cases, 

system (mv $Old $New);

will work.

There's a bit more detail in:

perldoc -f rename




Re: PROGRAM!

2001-06-20 Thread Me

[plz keep everthing on list unless there's
a particularly good reason to go off list]

  (I need the three data types that are'underlined'  and are in
'font
  size 14 large'

That sort of formatting doesn't work on this list.

(Btw, what you are calling 'data types' are really data items.
Integer and array are examples of data types.)

 and I have put 'stars around the data'

Good. That works.

 *086117*  00  BNY INTERNATIONAL LTD
 CO-OPERATIVE BANK   *THE CO-OPERATIVE BANK PLC*0021
A
 15/10/1999  M18/05/1999
301599
 00210100  002102  Y   NN
 14/11/1999  29-MAY-2001 N
 25/05/2001 05:185250M   03/10/1996
 21  GBM
 GMAC -Comercial CR Ltd  1   Brighton,
E.Sussex
 *Sovereign Hse   Church St
 Brighton   E.SussexBN1
 1SS* 01273   321211

Go ahead and try the coding approach I suggested in my last email.

You want to print out array elements 0 (for the ID), 3 (branch),
and -3 through -7 (address), at least I think that will work.

When you've typed in the code, run it as a perl script
and specify an input file on the command line that
contains the above record. See what you get.




Re: Sorting

2001-06-19 Thread Me

 Could someone tell me how to sort these files?

 As you can see they are already sorted in perl, but the problem is .7
is
 suppose to be before 10.

 to get this sort i used
 @list_of_files=sort @list_of_files;

 sorted EMX-1.15.0.17.37-EMX-1.15.0.17.36.dlcwrap
 sorted EMX-1.15.1.42.10-EMX-1.15.1.42.11.dlcwrap
 sorted EMX-1.15.1.42.10-EMX-1.15.1.42.9.dlcwrap
 sorted EMX-1.15.1.42.23-EMX-1.15.1.42.24.dlcwrap
 sorted EMX-1.15.1.42.24-EMX-1.15.1.42.25.dlcwrap
 sorted EMX-1.15.1.42.25-EMX-1.15.1.42.26.dlcwrap
 sorted EMX-1.15.1.42.7-EMX-1.15.1.42.8.dlcwrap
 sorted EMX-1.15.1.42.9-EMX-1.15.1.42.8.dlcwrap

A plain sort is equivalent to this:

sub stdsort { $a cmp $b };
@sorted = sort stdsort @unsorted;

$a and $b get set to array elements to be compared.
The sort code must return -1 if $a  $b, 0 if they are
the same, or 1 if $a  $b.

You need to do a custom sort procedure:

sub mysort { # compare $a and $b };
@sorted = sort mysort @unsorted;

For more general sort details, see

perldoc -f sort

In your specific case, you might want to separate
the text and numeric bits of $a/$b with a split on
'-' or maybe a regex, then breaking the numeric
down even further by splitting on '.', and then
separately comparing the bits like so:

$abit1 cmp $ bbit1 or
$abit2 = $bbit2 or
$abit3 = $bbit3 or ...

hth.




Re: Quick Perl Question

2001-06-19 Thread Me

  ($year, $month, $mday, $hour, $minute, $second, $timezone) =
  /^Rates as of (\d+).(\d+).(\d+) (\d+):(\d+):(\d+) (\w+) (.*)$/;
 
  The following code is pointless:
 
  $year   = $1;
  $month  = $2;
  $mday   = $3;
  $hour   = $4;
  $minute = $5;
  $second = $6;
  $timezone   = $7;
 
  ---
 
  Then you end the while loop!

 --- Disagree, The code is very relavent and allows the manipulation
of
 the date, time and timezone using Date::Manip before it is written to
 the file.

Well, the $year = $1 etc are definitely pointless.
The statement immediately prior has just set
the variables, so the $year = $1 simply overwrites
their values with exactly the same values as were
just assigned. Try:

($year, $month, $mday, $hour, $minute, $second, $timezone) =
/^Rates as of (\d+).(\d+).(\d+) (\d+):(\d+):(\d+) (\w+) (.*)$/;

print $year;

$year   = $1;

print $year;

and you will see that $year doesn't change in
between prints.

The ending of the loop is ok, but it means you'v
ended the loop. So the subsequent lines aren't
in a loop, so they all work on whatever happened
to be the last line in the input. Which is not what
you want. As I said:

  Everything that follows is working on the last line
  from the file. That makes no sense.



  Try the following and see if it works. Post to the list if there are
any
  problems with it.
 
  while (INFILE) {
 
  ($year, $month, $mday, $hour, $minute, $second, $timezone) =
  /^Rates as of (\d+).(\d+).(\d+) (\d+):(\d+):(\d+) (\w+)
(.*)$/;
 
  $year and last; # if we've matched the date line, then bail
out.
 
  eof and print STDERR Didn't find date line;
  }
 
  print OUTFILE $month/$year...;
 

 --- Returns empty strings.

I've taken another look, and I would expect it to either
print the error or print the match.

change the final print line to something like:

print OUTFILE TEST: $month/$year...;

and see if the 'TEST' appears.

If it does, well, it's as if the INFILE loop isn't happening.

  # Now have date info and we're part way through file
 
  while (INFILE) {
 
  ($cur_sym, $cur_desc, $usd_unit, $units_usd) =
  /^([A-Z]{3})( [A-Za-z]+)+\s+(\d+\.\d+)\s+(\d+\.\d+)\s*$/;
 

 -- Truncates $cur_desc after first word.

I've reflected briefly, and I've no idea on that.
I can't see how it's possible.


  Looses the date values.

Eh? What's this part got to do with the date values?
How can setting these variables have anything to do
with the other variables? I suspect I don't understand
your terminology here.




Re: Extracting data from a web page

2001-06-19 Thread Me

 Microsoft Excel has the ability to import data via a web query. If I
create
 a query and run it on the following URL, a table with stock price
 information will be displayed on an Excel worksheet.
 http://finance.yahoo.com/q?s=%5EIXIC+%5EDJI+RHAT++d=v1

 Now to the Perl/CGI question. What techniques and functions would I
use in
 Perl to retrieve data from the above URL and save to a comma delimited
data
 file?

I see two basic options:

Drive Excel using perl.
Use perl to do it all.

In the former case, I would suggest:

Use existing perl module to drive Excel using Automation

In the latter case, I would suggest:

Use existing perl module to get the content for the URL
Use existing perl module to parse the content
Write the code to write what you want to a CSV

To seek out existing modules, use cpan:

http://search.cpan.org/

hth.




Re: scope

2001-06-19 Thread Me

 If I define a function just in the freespace of a file and have
included in
 that file two packages which are bracketed in like:

 sub function {}

 package 1;
 {}

 package 2;
 {}



 How do I access the function (make a function call) from within one of
the
 packages?

 is it main::function or is it something else.

Yes.

 Also, is it ok to call functions which take no parameters as just the
 function name. like $var = function; as opposed to $var = function();

Yes.




Re: Extracting data from a web page

2001-06-19 Thread Me

 [how to do it in ten seconds]

Randal just wants to take all the fun (and work)
out of creating solutions.




Re: Quick Perl Question

2001-06-19 Thread Me

 printf OUTFILE %s\,%s\,%s\,%s\,%s\,%s\,%s\n,
 $date, $time, $tz, $cur_sym, $cur_desc, $usd_unit, $units_usd;

 close(INFILE);
 close(OUTFILE);
 print STDERR \n;

 1;

You seem to be misunderstanding one particular
aspect of perl. Given the following:

while (INFILE) {

# do something with each line encountered
# if condition, quit this while loop

}

# do something after first while loop

while (INFILE) {

# do something else with each line encountered
# if another condition, quit this while loop

}

# do something after second while loop

The first do something happens repeatedly until
the first condition applies or the end of INFILE
is reached, whichever comes first. In other words,
it can happen zero times, or a dozen times, or
whatever.

The 'do something after first while loop' happens once.

The second loop starts off, in terms of lines from the
INPUT file, where the first left off. Other than that, a
similar deal regarding the 'do something's applies
to this second set of perl code as it does to the first
set of perl code.

In your case, the printf is outside the loops, so it will
only happen once.

-

Other than that, given what printed, it's clear the second
regex isn't matching at all. This isn't too surprising -- I
didn't put a lot of effort in to it, so it might just be wrong.
If it doesn't match, then the variables aren't set.

To tighten the verification a little, add:

$started or print STDERR Didn't find a currency line;

after the second loop.

This will surely print out, which shows that the regex
didn't match. In other words:

($cur_sym, $cur_desc, $usd_unit, $units_usd) =
/^([A-Z]{3})( [A-Za-z])+\s+(\d+\.\d+)\s+(\d+\.\d+)\s*$/;

Doesn't match:

USD United States Dollars 1.0
1.0

I can't see why not.

One other possibility is that the second while loop
isn't even being entered; stick a print TEST at the
start of the second loop to verify that it is being
entered.




Re: Quick Perl Question

2001-06-19 Thread Me

 The second loop is executing.  The TEST statement worked.

Ok.

 The Currency part of the email has a fixed format that is never
 deviated from:
 
 1-3 $cur_sym
 4 space
 5-32 $cur_desc
 33-35 (3) spaces
 36-55 d8.d10 (.00)
 56-58 (3) spaces
 59-78 d8.d10 (.00)

This doesn't precisely match your example:

  USD United States Dollars 1.0
  1.0

This includes numbers that are space padded in front
and have just five zeroes after the decimal point (no
doubt also space padded for the remaining decimal
places).

 I tried to shorten it to match the $cur_sym only

Good move.

 but couldn't get it to work

Bummer.

 I also tried the following: 
 ($cur_sym, $cur_desc, $usd_unit, $units_usd) =
 /^([A-Z]{3}) ([A-Za-z]{28})   (\d{7}\.\d{10})   (\d{7}\.\d{10})\s*$/;

\d matches a digit. In your example, there are spaces
where the above regex expects digits.

Are you sure my original currency line regex isn't matching?

If you are still doing the print-after-the-loop-ends
thing, then the variables will naturally be empty,
because the loop ends when the regex fails
to match, hence setting all the variables to null
just before it exits the loop.

Going back to your attempt to get $cur_sym to 
match, try this as the first statements inside the
second loop:

($cur_sym) = /^([A-Z]{3})/;
print $cur_sym;

does that do anything?




Re: Quick Perl Question

2001-06-19 Thread Me

 Got a combination that sort of works.  It returns all the required
 fields but truncates any line where $usd_unit or $units_usd has more
 than 1 digit before the decimal point.  There can be as many as (8)
 digits before and (10) digits after the decimal point in both cases.
 
 Here's the regex I'm using:
 
 ($cur_sym, $cur_desc, $usd_unit, $units_usd) =
 /^([A-Z]{3})+\s+([A-Za-z\s]{28})+\s+(\d+\.\d+)+\s+(\d+\.\d+)/;

/^

matches start of line. Ok.

[A-Z]{3}

matches 3 uppercase letters. Ok. 

([A-Z]{3})+

matches 3, 6, 9, ... uppercase letters and puts the
last set of 3 in to $cur_sym. Probably not what you
meant. You should stick to what we had before:

([A-Z]{3})

with a space following as the next matching character
of the pattern.

\s+

matches one or more spaces. Ok.

([A-Za-z\s]{28})

matches the next 28 alpha or whitespace characters.
(whitespace means spaces or tabs or newlines.) Ok.

+

matches the previous 28 character atom 1 or more
times, and returns the last 28 character match as the
second variable ($cur_desc). Not what you want.
Remove this extraneous +.

\s+

matches one or more whitespace characters. ok.

(\d+\.\d+)

matches one or more digits, followed by one space,
followed by one or more digits. ok.

matches the previous atom 1 or more times. Again,
not what you want. Remove the extraneous +.

\s+

matches one or more whitespace characters. ok.

(\d+\.\d+)

matches one or more digits, followed by one space,
followed by one or more digits. ok.

/;

means that anything can follow the rest of the pattern.

I'd recommend tightening the pattern up by making the
end be:

\s+$/;

which matches any amount of whitespace and then the
end of the line.

Did you spot your mistake? I didn't, but I'll let you tidy
up your regex first and see if you don't spot your problem.




Re: Searching and printing a text file

2001-06-19 Thread Me

  while(logfile)
 {
   #if(#line I'm currently on is m/$searchstring/i)
   {
print;
   }

 Now the problem is, how do I specify The line I'm currently working
on?

That's easy -- you don't.

When you said:

print;

you didn't specify what to print. So print printed $_,
the default variable. Lots of functions either set or
get the default variable if you don't tell them to do
otherwise.

In the same vein:

while () {

(with or without a handle name in the s)
sets $_.

And:

if (/foo/) {

compares foo to $_.

Easy, huh?

Btw, the current line no is in $.

hth.




Re: Please suggest a better method...

2001-06-18 Thread Me

 tr{abcdefghijklmnoprstuvwxy}
   {222333444555666777888999};

or, for a smidgen extra legibility:

 tr{abc def ghi jkl mno prs tuv wxy}
   {222 333 444 555 666 777 888 999};





Fw: map function has me confused

2001-06-18 Thread Me

fy'all'si:

@newarray = map { local $_ = $_; s/foo/bar/; $_ } @oldarray;
 
   The use of the local operator ... adds little functionality
   other then readabillity, seeing how the map function is
   in { } meaning that $_ is local to the function anyway.

Minor point:

Note that this localizing doesn't apply to all { }. To summarize
Jos' email to me, this should say something more like

because the $_ is in map's {}, it's implicitly localised.

True, and another example of Perl just doing the right thing;
Perl generally localizes when you'd want it to anyway.


Major point:

Note also that the timing of the undo part of the implicit
localizing is not quite the same as the undo timing of an
explicit local. The net effect is that @oldarray gets changed
with implicit localizing, but not with the explicit one.




  1   2   >