getting filename in <>

2005-05-16 Thread Ramprasad A Padmanabhan
Hi all,
  I have a script that reads all input from the files specified in
commandline

like this 
while(<>){
 ...

}


Inside the loop can I get the filename of the file from which <> is
being read



Thanks
Ram



--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: getting filename in <>

2005-05-16 Thread John W. Krahn
Ramprasad A Padmanabhan wrote:
Hi all,
Hello,
  I have a script that reads all input from the files specified in
commandline
like this 
while(<>){
 ...

}
Inside the loop can I get the filename of the file from which <> is
being read
Yes, it is in the variable $ARGV
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Threads related document to refer in perl

2005-05-16 Thread Manav Mathur



|-Original Message-
|From: Gayatri [mailto:[EMAIL PROTECTED]
|Sent: Monday, May 16, 2005 10:40 AM
|To: beginners@perl.org
|Subject: Threads related document to refer in perl
|
|
|Hello Friends,
|
|
|
|I want to create threads using perl.
|
|So if any documents or links are there to refer please send me.
|

The Perl manual has an entire section devoted to this.
perldoc perlthrtut

|
|
|Thanking you in advance
|
|-Gayatri
|
|
|***NOTE
|***
|Deccanet Designs Ltd is now Flextronics Design Ltd, India
|***
|***
|
|
|
|*DISCLAIMER
|***
|This e-mail and any attachment is for authorised use by the intended
|recipient(s) only. It may contain proprietary material, confidential
|information and/or be subject to legal privilege of Flextronics Design Ltd.
|If you have received this message in error, please notify the originator
|immediately. If you are not the intended recipient, you are notified that
|you are strictly prohibited from retaining, using, copying, altering or
|disclosing the contents of this message.
|***
|***
|


*
Disclaimer:

The contents of this E-mail (including the contents of the enclosure(s) or 
attachment(s) if any) are privileged and confidential material of MBT and 
should not be disclosed to, used by or copied in any manner by anyone other 
than the intended addressee(s).   In case you are not the desired addressee, 
you should delete this message and/or re-direct it to the sender.  The views 
expressed in this E-mail message (including the enclosure(s) or attachment(s) 
if any) are those of the individual sender, except where the sender expressly, 
and with authority, states them to be the views of MBT.

This e-mail message including attachment/(s), if any, is believed to be free of 
any virus.  However, it is the responsibility of the recipient to ensure that 
it is virus free and MBT is not responsible for any loss or damage arising in 
any way from its use

*

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




Re: Help with subroutines

2005-05-16 Thread John Doe
Am Montag, 16. Mai 2005 06.03 schrieb Madhur Kashyap:
> Have a look at the code snippet from the perl program I have written

Hello,

> use strict;
> use FileHandle;
> use IPC::Open2;
>
> use vars { ... $topCellName ...};
>
> sub setup {
> ..
> $topCellName="crm_com";
>...
> }
>
> sub loadNxfDB {
>print "$_[0]";
>my $nxfDBFH=new FileHandle;
>open ($nxfDBFH,$_[0]) or die "Error: Cannot open cross-reference
> database, $_[0]\n";
> 
> return %nxfDB
> }
>
> sub updateNetPairsDB {
> my %nxfDB=&loadnxfDB ("/tmp/$topCellName/LVS/svdb/$topCellName.nxf");
> }
>
> sub main {
>  .
>   &updateNetPairsDB ();
> }
>
> &main ();
>
> ===
> The program quits whenever it tries to open the file in &loadNxfDB ()
> subroutine with this error
>
> Package Installation directory
> $BFE_INST_DIR=/mot/madhurk/meth1/dft/bridges/defect_bfault

> Prepairing environment ...
> Creating necessary directory structure ...
> /tmp /crm_com/LVS /svdb/ crm_com.nxf

Where is this coming from? The spaces in the path are here too.

> Error: Cannot open netname cross-reference database, /tmp /crm_com/LVS
> /svdb/ crm_com.nxf

This error msg is not coming from the die() in loadNxfDB(), the text is 
different ("netname").
(Without the "\n" ending strings passed to die/warn, you get the file names 
and line numbers of errors/warnings)

> Notice the spaces in the file path which I don't know why
> automatically gets inserted whenever I try to pass the file path
> scalar to the subroutine.
> ===
>
> Just to verify if I am not doing anything wrong, I tried to open the
> same file in the same fashion in a very small program which I am
> writing below and it worked.
>
> use strict;
> use FileHandle;
>
> my $topCell="crm_com";
> my $ret=&test ("/tmp/$topCell/LVS/svdb/$topCell.nxf");
> sub test {
>  my $FH=new FileHandle;
>  open ($FH,$_[0]) or die "Error: Cannot open file, $_[0]\n";
>  print $FH->getline;
>  close ($FH);
>  return 0;
> }
> ===
>
> Can someone help me debug this issue .its kinda urgent for me.

Non unlikely that the error is caused by code you have not posted.

joe

>
> --
> Regards
> Madhur Kashyap

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




Re: Help with subroutines

2005-05-16 Thread Madhur Kashyap
Ohh I am extremely sorry ... When I was trying to write the code
exceprt I forgot to add some lines but showed the log generated from
complete code.

> > sub loadNxfDB {
> >print "$_[0]";
> >my $nxfDBFH=new FileHandle;
> >open ($nxfDBFH,$_[0]) or die "Error: Cannot open netname cross-reference 
> > database, $_[0]\n";
> > 
> > return %nxfDB
> > }
> >
> > sub updateNetPairsDB {
> > my %nxfDB=&loadnxfDB ("/tmp/$topCellName/LVS/svdb/$topCellName.nxf");
> > }
> >
> > sub main {
> >  .
> >   &updateNetPairsDB ();
> > }
> >
> > &main ();

> > Package Installation directory
> > $BFE_INST_DIR=/mot/madhurk/meth1/dft/bridges/defect_bfault
> 
> > Prepairing environment ...
> > Creating necessary directory structure ...
> > /tmp /crm_com/LVS /svdb/ crm_com.nxf

> Where is this coming from? The spaces in the path are here too.

Please see the loadNxfDB routine above. In the very beginning I am
printing the argument that has been passed to the function.  I did
that for checking what's happening.

> > Error: Cannot open netname cross-reference database, /tmp /crm_com/LVS
> > /svdb/ crm_com.nxf
> 
> This error msg is not coming from the die() in loadNxfDB(), the text is 
> different ("netname").
> (Without the "\n" ending strings passed to die/warn, you get the file names 
> and line numbers of errors/warnings)

Thats not an error reported by perl, that string is generated by the
program itself to specify that there is some problem with the file
path specified. Consider that as a typo when I was writing the exceprt
of my code in the email.

-- 
Regards
Madhur Kashyap

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




select system call

2005-05-16 Thread Gayatri

Dear Friends,

I am facing one problem please let me know if anybody knows the solution.

The problem is as follows

   use IO::Select;
   use IO::Socket;
   

The variable  $sock  will be handling my socket id for TCP, AF_INET/PF_INET
family and the code is as shown bellow..
   Listen ($sock, 5); #listens on this socket

   $sel = new IO::Select( $sock );

   while(@ready = $sel->can_read) {
   foreach $fh (@ready) {
   if($fh == $lsn) {
   # Create a new socket
   $new = $lsn->accept;
   $sel->add($new);
   }
   else {
   # Process socket

   # Maybe we have finished with the socket
   $sel->remove($fh);
   $fh->close;
   }
   }
   }

even if there is event(connection/read/write) to be accepted, select returns
empty set most of the times.. even though other(client) is initiating
connection.
If anyone has come across such problem please let me know the solution. 


Thanks and Regards,
Gayatri


***NOTE*
**
Deccanet Designs Ltd is now Flextronics Design Ltd, India

**



*DISCLAIMER*
**
This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege of Flextronics Design Ltd.
If you have received this message in error, please notify the originator
immediately. If you are not the intended recipient, you are notified that
you are strictly prohibited from retaining, using, copying, altering or
disclosing the contents of this message.

**



***NOTE***
Deccanet Designs Ltd is now Flextronics Design Ltd, India
**



*DISCLAIMER***
This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege of Flextronics Design Ltd.
If you have received this message in error, please notify the originator
immediately. If you are not the intended recipient, you are notified that
you are strictly prohibited from retaining, using, copying, altering or
disclosing the contents of this message.
**

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




Re: Help with subroutines

2005-05-16 Thread John Doe
Am Montag, 16. Mai 2005 11.57 schrieb Madhur Kashyap:
> Ohh I am extremely sorry ... When I was trying to write the code
> exceprt I forgot to add some lines but showed the log generated from
> complete code.
>
> > > sub loadNxfDB {
> > >print "$_[0]";
> > >my $nxfDBFH=new FileHandle;
> > >open ($nxfDBFH,$_[0]) or die "Error: Cannot open netname
> > > cross-reference database, $_[0]\n"; 
> > > return %nxfDB
> > > }
> > >
> > > sub updateNetPairsDB {
> > > my %nxfDB=&loadnxfDB
> > > ("/tmp/$topCellName/LVS/svdb/$topCellName.nxf"); }
> > >
> > > sub main {
> > >  .
> > >   &updateNetPairsDB ();
> > > }
> > >
> > > &main ();
> > >
> > > Package Installation directory
> > > $BFE_INST_DIR=/mot/madhurk/meth1/dft/bridges/defect_bfault
> > >
> > > Prepairing environment ...
> > > Creating necessary directory structure ...
> > > /tmp /crm_com/LVS /svdb/ crm_com.nxf
> >
> > Where is this coming from? The spaces in the path are here too.
>
> Please see the loadNxfDB routine above. In the very beginning I am
> printing the argument that has been passed to the function.  I did
> that for checking what's happening.

Hmm... I don't have any idea where/why spaces are inserted between

 $topCellName="crm_com";
 loadnxfDB ("/tmp/$topCellName/LVS/svdb/$topCellName.nxf");

and

 sub loadNxfDB {
  print "$_[0]"; # btw: unneccessary double quotes
 } 


> > > Error: Cannot open netname cross-reference database, /tmp /crm_com/LVS
> > > /svdb/ crm_com.nxf
> >
> > This error msg is not coming from the die() in loadNxfDB(), the text is
> > different ("netname").
> > (Without the "\n" ending strings passed to die/warn, you get the file
> > names and line numbers of errors/warnings)
>
> Thats not an error reported by perl, that string is generated by the
> program itself 

Don't know the non-perl "program itself". 

Maybe somebody else could help?

> to specify that there is some problem with the file 
> path specified. Consider that as a typo when I was writing the exceprt
> of my code in the email.
>
> --
> Regards
> Madhur Kashyap

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




RE: Create Excel spreadsheets

2005-05-16 Thread Bob Showalter
Peter Rabbitson wrote:
> I am about to start on a project that will be creating various excel
> files. Cpan yields quite a number of posibilities, among which
> Spreadsheet::WriteExcel looks most promising. I just wanted to hear
> some opinions on the best tool for the job before I delve into a
> certain inetrface.
> The resulting files must have multiple workbooks and be able to
> contain embedded images. The rest (numbers, text formatting) seems
> trivial through any interface.
> All thoughts/suggestions appreciated.

I have used Spreadsheet::WriteExcel with great success to create workbooks
from Unix. It can definitely create files with multiple worksheets. I don't
know about images though; I have never had that need.

If you are on a Windoze server environment, you have the option of the
various OLE automation routes...

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




Anyone installed Net::LDAPapi

2005-05-16 Thread Ramprasad A Padmanabhan
I am not able to install Net::LDAPapi , 
I looked up google, seems that the module is no longer supported.
Sad, I thought the interface of Net::LDAPapi is really gr8 

Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: Anyone installed Net::LDAPapi

2005-05-16 Thread Peter Scott
On Mon, 16 May 2005 17:57:16 +0530, Ramprasad A Padmanabhan wrote:

> I am not able to install Net::LDAPapi , 
> I looked up google, seems that the module is no longer supported.
> Sad, I thought the interface of Net::LDAPapi is really gr8 

Net::LDAP is still supported and has a very good interface.  I frequently
write whole programs using it without looking at the documentation once.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


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




Re: Errors on processing 2GB XML file by using XML:Simple

2005-05-16 Thread Nan Jiang
Hi all,
I have tried to use XML:Twig to parse a 2GB XML file instead of using 
XML:Simple, but I still got an error "The memory couldn't be written". My 
Perl is the latest and my RAM is 1GB.

Anyone got suggestions?
Thanks a lot,
Nan
From: Peter Rabbitson <[EMAIL PROTECTED]>
To: beginners@perl.org
Subject: Re: Errors on processing 2GB XML file by using XML:Simple
Date: Fri, 13 May 2005 09:46:09 -0500
> I keep receiving virtual memory error and program runtime error while 
using
> XML:simple to process a 2GB XML file on Windows 2000. I have changed
> virtual memory to 4 GB but still no use, so I wonder if anyone could 
offer
> some help? Or is there any better module to process a 2GB XML file?
>

XML::Twig is your answer. Very clear documentation and examples. Enjoy
--
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: Errors on processing 2GB XML file by using XML:Simple

2005-05-16 Thread Peter Rabbitson
> I have tried to use XML:Twig to parse a 2GB XML file instead of using 
> XML:Simple, but I still got an error "The memory couldn't be written". My 
> Perl is the latest and my RAM is 1GB.

Are you issuing a $twig->purge at the end of each handler? Without it memory 
is not implicitly released (no garbage collection so to speak). Or maybe you 
are trying to construct a twig with a malformed root and you are ending up 
reading the entire file (in other words the twig does not know when to stop 
until it runs out of data, or in your case runs out of memory).

Peter

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




Re: Errors on processing 2GB XML file by using XML:Simple

2005-05-16 Thread Nan Jiang
Hi Peter,
Basically, the XML file has two key parallelled nodes:  and 
. If there is a  child existing in , 
 node will be existing for showing more detailed information 
about the content of this  such as  and .

However, not every  node has one or more  child, so I need to 
write a loop to find out if  is a child of  nodes. If there 
are some  nodes existing, I will check each of  to 
output more information.



1


Top/


2


205108
http://www.britishhorrorfilms.co.uk/rillington.shtml"/>
http://www.shoestring.org/mmi_revs/10-rillington-place.html"/>


http://www.britishhorrorfilms.co.uk/rillington.shtml";>
British Horror Films: 10 Rillington Place
Review which looks at plot especially the shocking features 
of it.
Top/Arts/Movies/Titles/1/10_Rillington_Place


http://www.shoestring.org/mmi_revs/10-rillington-place.html";>
MMI Movie Review: 10 Rillington Place
Review includes plot, real life story behind the film and 
realism in the film.
Top/Arts/Movies/Titles/1/10_Rillington_Place



I have put as many Twig->purge at the end of each loop. However, my problem 
is, when I run the program, I can hear the hardisk is being read but after a 
while, a Windows Memory Error pops up and the program halt. The only root I 
can say is  because  and  are parallelled inside 


Thanks again,
Nan
From: Peter Rabbitson <[EMAIL PROTECTED]>
To: beginners@perl.org
Subject: Re: Errors on processing 2GB XML file by using XML:Simple
Date: Mon, 16 May 2005 08:08:01 -0500
> I have tried to use XML:Twig to parse a 2GB XML file instead of using
> XML:Simple, but I still got an error "The memory couldn't be written". 
My
> Perl is the latest and my RAM is 1GB.

Are you issuing a $twig->purge at the end of each handler? Without it 
memory
is not implicitly released (no garbage collection so to speak). Or maybe 
you
are trying to construct a twig with a malformed root and you are ending up
reading the entire file (in other words the twig does not know when to stop
until it runs out of data, or in your case runs out of memory).

Peter
--
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: Errors on processing 2GB XML file by using XML:Simple

2005-05-16 Thread Peter Rabbitson
> Basically, the XML file has two key parallelled nodes:  and 
> . If there is a  child existing in , 
>  node will be existing for showing more detailed information 
> about the content of this  such as  and .
> 
> However, not every  node has one or more  child, so I need 
> to write a loop to find out if  is a child of  nodes. If 
> there are some  nodes existing, I will check each of  
> to output more information.

Can you provide some relevant code? Looking at the sample xml two handlers 
immediately come to mind, one for RDF/Topic another for RDF/ExternalPage, 
both calling different subroutines that use some kind of shared variables as 
flags indicating which  are we currently in, and which links are we 
looking for when parsing through ExternalPages.

Unless both of your  and  are randomly intermixed 
(very very very unlikely) and if they are - then you are really screwed :)

Peter

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




Re: Errors on processing 2GB XML file by using XML:Simple

2005-05-16 Thread Nan Jiang
Hi Peter,
The codes which are quite straightforward are below:
#!/usr/bin/perl
use warnings;
use strict;
use XML::Twig;
my $twig= new XML::Twig;
$twig->parsefile( "./content.example.txt"); #open XML file
my $root = $twig->root; #set root
chdir "F:/httpserv"; #set initial directory
foreach my $topic ($root->children('Topic')) {
if ($topic->children('link')){ #if element  is a child of , 
change directory for index writing
chdir $topic->att('r:id');
foreach my $link ($topic->children('link')) {
foreach my $extpage ($root->children('ExternalPage')) {
if ($link->att('r:resource') eq $extpage->att('about')){
print $extpage->first_child_text('d:Title'), "\n";
print $extpage->first_child_text('d:Description'), "\n";
$twig->purge; #I'm not sure if I need to purge in each loop.
}
}
$twig->purge;
}
$twig->purge;
chdir "F:/httpserv"; #reset directory pointer to local root directory
}
}

While I think  and  are not randomly intermixed as 
 nodes are generated in relevant categories such as  -> 
 ->  and then if the  has  
children which means it is a final category, then  nodes 
appeared immediatly below the  with the same order as .

Thanks again,
Nan
From: Peter Rabbitson <[EMAIL PROTECTED]>
To: beginners@perl.org
Subject: Re: Errors on processing 2GB XML file by using XML:Simple
Date: Mon, 16 May 2005 08:25:03 -0500
> Basically, the XML file has two key parallelled nodes:  and
> . If there is a  child existing in ,
>  node will be existing for showing more detailed 
information
> about the content of this  such as  and 
.
>
> However, not every  node has one or more  child, so I 
need
> to write a loop to find out if  is a child of  nodes. If
> there are some  nodes existing, I will check each of 

> to output more information.

Can you provide some relevant code? Looking at the sample xml two handlers
immediately come to mind, one for RDF/Topic another for RDF/ExternalPage,
both calling different subroutines that use some kind of shared variables 
as
flags indicating which  are we currently in, and which links are we
looking for when parsing through ExternalPages.

Unless both of your  and  are randomly intermixed
(very very very unlikely) and if they are - then you are really screwed :)
Peter
--
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: How to get the numeric index of a element in an array

2005-05-16 Thread Frank
Hi, thanks all!   I have solve my problem.   But I have another question 
now,

How to determin whether I reach the end of file  in Perl program?   Also 
, can you tell me where I can get these informations .  I scan the 
"programing perl " by Larry Wall,  But it is diffculty to find what I 
want from such a cyclopaedia.

Thanks
Frank
bright true wrote:
hello ,
 
you can do something like the following
 
my $counter = -1;
foreach (@array){
$counter++;
if($_ =~m/$word/){
print "Element ID is $counter";}
}

 
On 5/15/05, *Frank* <[EMAIL PROTECTED] > wrote:

Ing. Branislav Gerzo wrote:
>Frank [F], on Sunday, May 15, 2005 at 19:45 (+0800) typed:
>
>F> If i know the element of array, can I get the numeric
index  of this
>F> element?
>
>Exist a way, but it is better using hash. In arrays you have to
>iterate over every element.
>
>
~~~Pls tell me the way. possibly I need use it. I need get the
elements from an array after some specific element. Say, I find a
elements contains the word I want by regular expression ($_ =~
/word1/),
and then I need get the following element untill another words appears
($_ =~ /word2/). I thought the best way for me is to get the numeric
index of the elements and get the elements i want. Do you have any
suggestions?
>
>
>
Thanks,
Frank
--
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: How to get the numeric index of a element in an array

2005-05-16 Thread Ing. Branislav Gerzo
Frank [F], on Monday, May 16, 2005 at 21:34 (+0800) wrote the
following:

F> How to determin whether I reach the end of file  in Perl program?   Also
F> , can you tell me where I can get these informations .  I scan the 
F> "programing perl " by Larry Wall,  But it is diffculty to find what I
F> want from such a cyclopaedia.

maybe you read file in while loop. If it is EOF, it returns 'undef',
so while condition ends (while will execute something if condition
returns true)
So:
while(<$fh>) {
  print;
}

--

How do you protect mail on web? I use http://www.2pu.net

[When the carpal hits the fan...look out for flying electrons !]



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




Re: $variables in a string

2005-05-16 Thread Jeff 'japhy' Pinyan
On May 15, Paul D. Kraus said:
Hello,
my $image = Image::Magick->new;
# trouble
open(IMAGE, 'open(IMAGE, "That needs to be
  open(IMAGE, "
That's because the variable name is 'sku', not 'sku_unprocessed'.
--
Jeff "japhy" Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Errors on processing 2GB XML file by using XML:Simple

2005-05-16 Thread Peter Rabbitson
On Mon, May 16, 2005 at 01:33:15PM +, Nan Jiang wrote:
> While I think  and  are not randomly intermixed as 
>  nodes are generated in relevant categories such as  -> 
>  ->  and then if the  has  
> children which means it is a final category, then  nodes 
> appeared immediatly below the  with the same order as .
> 

The problem is that you completely misunderstood the idea of XMLtwig. You 
parse as you go. Here is the code that gives somewhat similar to your 
output. Don't get surprised by the ->simplify I use to deconstruct twigs - I 
am just used to it and it is merely a matter of style. You can very well use 
parent firstchild att and family. And remember - when working with XML::Twig 
Data::Dumper takes a whole new meaning :)

#!/usr/bin/perl

use warnings;
use strict;
use XML::Twig;

my $xml = '

1



Top/



2



205108
http://www.britishhorrorfilms.co.uk/rillington.shtml"/>
http://www.shoestring.org/mmi_revs/10-rillington-place.html"/>


http://www.britishhorrorfilms.co.uk/rillington.shtml";>
British Horror Films: 10 Rillington Place
Review which looks at plot especially the shocking features
of it.
Top/Arts/Movies/Titles/1/10_Rillington_Place


http://www.shoestring.org/mmi_revs/10-rillington-place.html";>
MMI Movie Review: 10 Rillington Place
Review includes plot, real life story behind the film and
realism in the film.
Top/Arts/Movies/Titles/1/10_Rillington_Place

';

my %want_links;

my $parser = XML::Twig->new (   twig_handlers => {  'Topic' => \&_topic_handler,
'ExternalPage' => 
\&_links_handler },
);

$parser->parse($xml);   #parse XML data

exit 0;


sub _topic_handler {

my ($twig, $child) = @_;
my $topic = $child->simplify (forcearray => 1);

if ($topic->{link}) {
%want_links = map { $_->{'r:resource'}, $topic->{'r:id'} } 
@{$topic->{link}};   #generate hash 'link_name' => 'directory'
}
else {
%want_links = ();   #reset the hash since we are working on a new 
topic (no more external links)
}

$twig->purge;
}

sub _links_handler {

my ($twig, $child) = @_;
my $ext_page = $child->simplify (forcearray => 1);

if ($want_links{$ext_page->{about}}) {
#chdir $want_links{$ext_page->{about}}  #commented out since I don't 
have that dir
print join ("\n",   $want_links{$ext_page->{about}},
$ext_page->{'d:Title'}[0],
$ext_page->{'d:Description'}[0],
);
print "\n\n";
}

$twig->purge;
}


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




Re: Errors on processing 2GB XML file by using XML:Simple

2005-05-16 Thread Nan Jiang
Hi Peter,
Thank you so much for your advice. I'll try to understand what you write and 
let you know the results!

Best wishes,
Nan
From: Peter Rabbitson <[EMAIL PROTECTED]>
To: beginners@perl.org
Subject: Re: Errors on processing 2GB XML file by using XML:Simple
Date: Mon, 16 May 2005 09:31:15 -0500
On Mon, May 16, 2005 at 01:33:15PM +, Nan Jiang wrote:
> While I think  and  are not randomly intermixed 
as
>  nodes are generated in relevant categories such as  ->
>  ->  and then if the  has 
> children which means it is a final category, then  nodes
> appeared immediatly below the  with the same order as .
>

The problem is that you completely misunderstood the idea of XMLtwig. You
parse as you go. Here is the code that gives somewhat similar to your
output. Don't get surprised by the ->simplify I use to deconstruct twigs - 
I
am just used to it and it is merely a matter of style. You can very well 
use
parent firstchild att and family. And remember - when working with 
XML::Twig
Data::Dumper takes a whole new meaning :)

#!/usr/bin/perl
use warnings;
use strict;
use XML::Twig;
my $xml = '

1


Top/


2


205108
http://www.britishhorrorfilms.co.uk/rillington.shtml"/>
http://www.shoestring.org/mmi_revs/10-rillington-place.html"/>

http://www.britishhorrorfilms.co.uk/rillington.shtml";>
British Horror Films: 10 Rillington Place
Review which looks at plot especially the shocking features
of it.
Top/Arts/Movies/Titles/1/10_Rillington_Place

http://www.shoestring.org/mmi_revs/10-rillington-place.html";>
MMI Movie Review: 10 Rillington Place
Review includes plot, real life story behind the film and
realism in the film.
Top/Arts/Movies/Titles/1/10_Rillington_Place

';
my %want_links;
my $parser = XML::Twig->new (   twig_handlers => {  'Topic' => 
\&_topic_handler,
'ExternalPage' => 
\&_links_handler },
);

$parser->parse($xml);   #parse XML data
exit 0;
sub _topic_handler {
my ($twig, $child) = @_;
my $topic = $child->simplify (forcearray => 1);
if ($topic->{link}) {
%want_links = map { $_->{'r:resource'}, $topic->{'r:id'} } 
@{$topic->{link}};   #generate hash 'link_name' => 'directory'
}
else {
%want_links = ();   #reset the hash since we are working on a 
new topic (no more external links)
}

$twig->purge;
}
sub _links_handler {
my ($twig, $child) = @_;
my $ext_page = $child->simplify (forcearray => 1);
if ($want_links{$ext_page->{about}}) {
#chdir $want_links{$ext_page->{about}}  #commented out since I 
don't have that dir
print join ("\n",   $want_links{$ext_page->{about}},
$ext_page->{'d:Title'}[0],
$ext_page->{'d:Description'}[0],
);
print "\n\n";
}

$twig->purge;
}
--
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: Threads related document to refer in perl

2005-05-16 Thread Dave Gray
> I want to create threads using perl.
> 
> So if any documents or links are there to refer please send me.

Here's some pretty basic threading code:
 

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




Attempt to free unreferenced scalar

2005-05-16 Thread Octavian Rasnita
Hi,

After running a program, I saw the following errors:

Attempt to free unreferenced scalar: SV 0x38bd0a4, Perl interpreter:
0x162445c
 at E:/usr/lib/Errno.pm line 15 (#1)
Attempt to free unreferenced scalar: SV 0x38bd0a4, Perl interpreter:
0x162445c at E:/usr/lib/Errno.pm line 15.

I can't see any other errors.

I have run the program again, but it didn't give me any errors.


Strange...

Teddy



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




RE: Help with subroutines

2005-05-16 Thread Charles K. Clarkson
Madhur Kashyap  wrote:

: Ohh I am extremely sorry ... When I was trying to write the code
: exceprt I forgot to add some lines but showed the log generated from
: complete code.

Can you reproduce the error in an example which we can run?
If not, we will probably need to see all your code.




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




Re: How to get the numeric index of a element in an array

2005-05-16 Thread Frank
Thanks!  Mr. Clarkson's  program really works.  but because my array 
(data) is more complex. So I made an adjustment but it did not work very 
well.

BTW: John W. Krahn suggested I can change  Input Record Separator, it 
does work and help me to solve the problem!   But I just wonder why the 
following program can not work very well and what's wrong with it!.   
Thanks very much!

# there is a  trailing record separator "\n" at end of every elemnet
my @items = qw(
   >blue
sky
skirt
sea
   >common_white
   paper
   flower
   feather
   >red
face
flower  
   >milk_white
   milk
   ivory
   >green
   grand
   tree
);

my $after_white;
foreach my $item ( @items ) {
$after_white = 1 if $item =~ /white$/;
   if ( $after_white ) {
   print "$item\n";
   next if $item =~ /^>/;
   $after_white = undef;
   }
}
__END___
The results given like this, it seems the loop works only for one time
>common_white
paper
>milk_white
milk

:-)THANKS
Charles K. Clarkson wrote:
my @items = qw(
   >blueskyskirtsea
   >white   paper  flower   >red
   face flower >green   grand   tree
);
my $after_white;
foreach my $item ( @items ) {
   if ( $after_white ) {
   last if $item =~ /^>?red$/;
   print "$item\n";
   }
   $after_white = 1 if $item =~ /^>?white$/;
}
__END__
HTH,
Charles K. Clarkson
 


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



RE: How to get the numeric index of a element in an array

2005-05-16 Thread Charles K. Clarkson
Frank  wrote:
 
: The results given like this, it seems the loop works only for one time
: 
:  >common_white
: paper
:  >milk_white
: milk

 This is what you asked perl to do. Let's walk the script.

First time through $item is ">blue". Since $after_white tests false,
this is what happens (nothing).

foreach my $item ( @items ) {
$after_white = 1 if $item =~ /white$/;
if ( $after_white ) {
}
}

Next time through $item is "sky". Since $after_white tests false,
this is what happens (nothing).

foreach my $item ( @items ) {
$after_white = 1 if $item =~ /white$/;
if ( $after_white ) {
}
}

Next time through $item is "skirt". Since $after_white tests false,
this is what happens (nothing).

foreach my $item ( @items ) {
$after_white = 1 if $item =~ /white$/;
if ( $after_white ) {
}
}

Next time through $item is "sea". Since $after_white tests false,
this is what happens (nothing).

foreach my $item ( @items ) {
$after_white = 1 if $item =~ /white$/;
if ( $after_white ) {
}
}

Next time through $item is ">common_white". Since both
$after_white and "$item =~ /^>/" test true, this is what
happens.

foreach my $item ( @items ) {
$after_white = 1 if $item =~ /white$/;
if ( $after_white ) {
print "$item\n";
next if $item =~ /^>/;
}
}

Next time through $item is "paper". Since $after_white tests true,
but "$item =~ /^>/" tests false, this is what happens. Note that
$after_white will test false after this.

foreach my $item ( @items ) {
$after_white = 1 if $item =~ /white$/;
if ( $after_white ) {
print "$item\n";
next if $item =~ /^>/;
$after_white = undef;
}
}

Next time through $item is "flower". Since $after_white tests
false, this is what happens (nothing).

foreach my $item ( @items ) {
$after_white = 1 if $item =~ /white$/;
if ( $after_white ) {
}
}


Do you see the error now? You told perl to stop after the second
line was printed. You didn't give a stopping point like you did last
time.

You need a small ego to be a computer programmer. You are very
unlikely to run into a perl bug. Assume every problem you have as
your own fault. This often means stepping through a script one line
at a time to find your error.

HTH,

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






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




Re: Attempt to free unreferenced scalar

2005-05-16 Thread Dave Gray
> After running a program, I saw the following errors:
> 
> Attempt to free unreferenced scalar: SV 0x38bd0a4, Perl interpreter:
> 0x162445c
>  at E:/usr/lib/Errno.pm line 15 (#1)
> Attempt to free unreferenced scalar: SV 0x38bd0a4, Perl interpreter:
> 0x162445c at E:/usr/lib/Errno.pm line 15.

The only time I've seen errors like that is in threading code that
uses non-threadsafe modules. What does your program do?

If you care enough, you might want to read up[1] and identify
suspicious code, then try to write an example that consistently throws
that error.

[1] 


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




Re: Attempt to free unreferenced scalar

2005-05-16 Thread Octavian Rasnita
My program just prints a web page and it doesn't use threads. It should run
under mod_perl (but it gives those errors when running it from command
line).

It uses more functional modules that get data from a MySQL database, and an
OOP module that prints the header, initialize the CGI object, the
CGI::Session object, the Template-Toolkit object...

Now I know why the program doesn't give that error when I run it for the
second time. It uses Template-Toolkit, and it creates a temp script which is
used the next time the program is launched, so it doesn't need to parse the
templates anymore.

I would try to make that OOP module to be a functional one, but I cannot use
CGI::Session from a functional module, because CGI::Session it gives an
error if I say something like:

our $session = CGI::Session->new(...);

I need to say:

my $session = CGI::Session->new(...);

so I cannot access CGI::Session from outside the module is used.

I will try to find what could be the problem, because I need to solve it.

Thank you.

Teddy


- Original Message - 
From: "Dave Gray" <[EMAIL PROTECTED]>
To: 
Sent: Monday, May 16, 2005 7:44 PM
Subject: Re: Attempt to free unreferenced scalar


> After running a program, I saw the following errors:
>
> Attempt to free unreferenced scalar: SV 0x38bd0a4, Perl interpreter:
> 0x162445c
>  at E:/usr/lib/Errno.pm line 15 (#1)
> Attempt to free unreferenced scalar: SV 0x38bd0a4, Perl interpreter:
> 0x162445c at E:/usr/lib/Errno.pm line 15.

The only time I've seen errors like that is in threading code that
uses non-threadsafe modules. What does your program do?

If you care enough, you might want to read up[1] and identify
suspicious code, then try to write an example that consistently throws
that error.

[1]


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




Time::localtime help

2005-05-16 Thread Matt Kopeck
Hi,

I have the following code:

use strict;

use Time::localtime;
my $now = localtime;

printf("The current date is %04d-%02d-%02d\n", $now->year+1900,
($now->mon)+1, $
now->mday);

It outputs the date in such a format: "The current date is 2005-05-16".
 I would like the name of the month(ex. 'May') displayed instead of 05. 
What is the easiest way to do this?

Thanks,
Matt

DISCLAIMER*
This e-mail and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed.  If 
you are not the named addressee, please notify the sender immediately by e-mail 
if you have received this e-mail by mistake and delete this e-mail from your 
system. If you are not the intended recipient you are notified that using, 
disclosing, copying or distributing the contents of this information is 
strictly prohibited.
DISCLAIMER*

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




Re: Time::localtime help

2005-05-16 Thread Peter Rabbitson
> printf("The current date is %04d-%02d-%02d\n", $now->year+1900,
> ($now->mon)+1, $
> now->mday);
> 
> It outputs the date in such a format: "The current date is 2005-05-16".
>  I would like the name of the month(ex. 'May') displayed instead of 05. 
> What is the easiest way to do this?
> 
The most most easiest is to create your own dictionary:

my %month = (   0 => 'Jan',
1 => 'Feb',
2 => 'Mar',

11 => 'Dec',
);

and then access it from $month{$now->mon}

Peter


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




RE: Time::localtime help

2005-05-16 Thread Charles K. Clarkson
Matt Kopeck  wrote:
 
: use strict;
: 
: use Time::localtime;
: my $now = localtime;
: 
: printf("The current date is %04d-%02d-%02d\n", $now->year+1900,
: ($now->mon)+1, $
: now->mday);
: 
: It outputs the date in such a format: "The current date is
:  2005-05-16". I would like the name of the month(ex. 'May') displayed
: instead of 05.
:
: What is the easiest way to do this?

A lot depends are you definition of easy. I am familiar with the
formats used in the POSIX stringify time function which expects the
built-in version of localtime(). This makes it easy for me to use
strftime(). YMMV.


use strict;
use warnings;
use POSIX 'strftime';

print strftime "The current date is %Y-%b-%d", localtime();

__END__


HTH,

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


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




Programs that code themselves

2005-05-16 Thread BJ
I was wondering how people approach problems that call for some of teh 
code to be generated on teh fly. I think a simple example would be a 
program for a teacher that imports a file, students.txt and produces a 
tk form with each students name and a pull down menu with the 5 possible 
grades for the school: a,b,c,d,f. Could this be done in one program? My 
current skills would lead me towards making a meta program that would 
import the text file and loop over it generating the tk code wich would 
be outputted in the form of a different script that was tailored to the 
list, but this seems rather impractical. I find myself doing this quite 
often though, so I thougth I would get others advice on it. Thank you. 
~Erithid

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



Re: columnwise analysis

2005-05-16 Thread Xavier Noria
On May 14, 2005, at 19:47, Aditi Gupta wrote:
there are actuaaly no fields specified.. i have strings in each row 
(with intermittent hyphens) and i've to find which alphabet occurs  
how many times in each column and then perform reg exp operations..  
but i've never dealt with such columnwise analysis before and  
haven't seen in books also so far.. which documentationshould i  
refer for such problem..
From that description my guess is that we have:
my @cols = split /\s*-\s*/, $row;
If an "alphabet" can have a stringfied representation, a code for  
example, and if given a $col we imagine for the sake of this followup  
a function that guesses $col's alphabet code:

my $code = guess_alphabet($col);
then a possible approach would be:
my @counters = ();
while (my $row = <$fh>) {
my @cols = split /\s*-\s*/, $row;
for (my $i = 0; $i < @cols; ++$i) {
my $code = guess_alphabet($cols[$i]);
++$counters[$i]{$code};
}
}
That's to be taken as pseudocode (I wrote it just inline), and  
needing adjusts taking into account details of the actual problem to  
solve.

The main idea is that we have an array of counters called @counters.  
The ith element of @counters contains counters per alphabet  
corresponding to the ith column in the input file.

To distinguish counters per alphabet at column $i, we store a hashref  
at $counters[$i], whose keys are alphabet codes, and whose values are  
counters per alphabet. That is, $counters[$i]{$code} gives how many  
times alphabet with code $code has been seen in the $ith column.  
Alphabets not seen at column $i have no entry, but $counters[$i] 
{$code} would evaluate to undef without problem.

Does that help? Can you apply regexps as you need with that structure?
-- fxn
PS: Notice that we don't explicity create the hashref to be stored at  
$counters[$i], we directly write $counters[$i]{$code}. That's thanks  
to a nice feature of Perl called "autovivification" that creates  
structures on the fly for you.

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



Re: Programs that code themselves

2005-05-16 Thread Chris Devers
On Mon, 16 May 2005, BJ wrote:

> I was wondering how people approach problems that call for some of
> [the] code to be generated on [the] fly.

Yes. See

perldoc -f eval

You can build up a string with arbitrary Perl code, then eval it to
execute it in place. People do this sort of thing all the time.



-- 
Chris Devers

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




Re: Net:FTP ->quot issue cmd to AS/400

2005-05-16 Thread Wiggins d'Anconia
Brian Volk wrote:
> Hi All,
>  
> I would like to issue a command to an AS/400 using Net:FTP -> quot(CMD
> [,ARGS]) but I'm having a little trouble.  Has anyone ever done this before?
> Any help would be greatly appreciated.
>

I have done this before but couldn't find the sample code.

> Here is what I would type on a 400 cmd line.  
>  
> quote rcmd pgm(kieth/quotetest)
>  
> Below is what I have so far 
>  
>  
> #!/usr/bin/perl 
>  
> use strict;
> use warnings;
> use Net::FTP;
>  
> my $hostname = '10.3.1.3';
> my $username = 'username';
> my $password = 'password';
>  
> # Open the connection to the host
> 
> my $ftp = Net::FTP->new($hostname);
> $ftp->login($username, $password); 
>  
> # this does not work
> ftp->quot(rcmd pgm["kiethb", "quotetest"]);   

The above might need to be quoted differently so that Perl interprets it
correctly. I thought it would throw a compile time error, but it
doesn't. Not to mention the missing sigil in front of 'ftp'. Did you try
correcting the missing '$', and explicitly quoting the parts:

$ftp->quot('rcmd','pgm["kiethb","quotetest"]');

??

>  
> # I tried using the system cmd as well ...no luck
> system "quote rcmd pgm(kieth/quotetest)";
>

This is unrelated. That is sending it to your local shell, not the
remote system.

> $ftp->quit;
>  
> Thanks!
>  
> Brian Volk
> HP Products
> 317.298.9950 x1245
>   [EMAIL PROTECTED]
>  

You should be able to get it to work with Net::FTP, I have in the past.
Obviously if you can get any sort of logging on teh AS400 side to tell
you what is happening during your session you should.  You can also turn
on the 'Debug' option to the constructor to get more verbosity on the
client side.

HTH,

http://danconia.org

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




Re: Time::localtime help

2005-05-16 Thread John W. Krahn
Matt Kopeck wrote:
Hi,
Hello,
I have the following code:
use strict;
use Time::localtime;
my $now = localtime;
printf("The current date is %04d-%02d-%02d\n", $now->year+1900,
($now->mon)+1, $
now->mday);
It outputs the date in such a format: "The current date is 2005-05-16".
 I would like the name of the month(ex. 'May') displayed instead of 05. 
What is the easiest way to do this?
The easiest way is to use localtime() in scalar context.
$ perl -le'
my $now = localtime;
print $now;
'
Mon May 16 12:31:07 2005
$ perl -le'
printf "The current date is %04d-%s-%02d\n",
( localtime =~ /(\w{3})\s+(\d+)\s+[\d:]{8}\s+(\d{4})/ )[ 2, 0, 1 ];
'
The current date is 2005-May-16

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



Re: Threads related document to refer in perl

2005-05-16 Thread Wiggins d'Anconia
Dave Gray wrote:
>>I want to create threads using perl.
>>
>>So if any documents or links are there to refer please send me.
> 
> 
> Here's some pretty basic threading code:
>  
> 

Good article on the subject:

http://www.perl.com/pub/a/2002/09/04/threads.html

http://danconia.org

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




Very simple question.

2005-05-16 Thread Tony Marquis
I'm creating a script that open a directory.
create a file call lock
Work in the directory.
delete the lock file and quit.

my ($rep_em) = "/test";

opendir (DIR, $rep_em) || die ("Error open directory $rep_em.");
chdir($rep_em) || die ("Error change directory to $rep_em");
my @fic = readdir(DIR);
open(LOCK , '>lock') || die ("Unable to create the lock file.");
foreach (@fic) {
if (!(($_ eq ".") || ($_ eq "..") || ($_ eq "lock"))) {
printf ("%s \n", $_);
}
}
close(DIR);
unlink(LOCK) || die ("Unable to delete the lock file.");

I'm able to delete the file manually but when i run the script under the
same user i get an error Unable to delete the lock file at line xx.

Thank for your help.


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




Re: Very simple question.

2005-05-16 Thread Philip M. Gollucci
Tony Marquis wrote:
I'm creating a script that open a directory.
create a file call lock
Work in the directory.
delete the lock file and quit.
my ($rep_em) = "/test";
opendir (DIR, $rep_em) || die ("Error open directory $rep_em.");
chdir($rep_em) || die ("Error change directory to $rep_em");
my @fic = readdir(DIR);
open(LOCK , '>lock') || die ("Unable to create the lock file.");
foreach (@fic) {
if (!(($_ eq ".") || ($_ eq "..") || ($_ eq "lock"))) {
printf ("%s \n", $_);
}
}
close(DIR);
unlink(LOCK) || die ("Unable to delete the lock file.");
I'm able to delete the file manually but when i run the script under the
same user i get an error Unable to delete the lock file at line xx.
Thank for your help.
 

At least two things
closedir DIR or die "failed $!";
perldoc -f unlink
doesn't take a file handle/glob LOCK, but a string 'lock'.
You should probably put the unlink in an END {} block so its always 
executed if you fail inbetween the locking for
a random reason.


--
END
--
Philip M. Gollucci ([EMAIL PROTECTED]) 301.254.5198
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com 

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



Compare to multiple numbers

2005-05-16 Thread christopher . l . hood
Why doesn't this work to check the  until it is one of the numbers
"1 2 3 4 5" ?? I have tried multiple variations of this with different
brackets ie. [ ] , and ( ) .

 

until($type_number == 1 .. 5 ){ 

print "Enter the number that corresponds to the type of offense you would
like a report for\n";

print "1. Virus\n2.Spam\n3.Hacking\n4.Copyright\n5.Child Pornography\n";

chomp($type_number = );

}

 

 

Chris Hood 

 



RE: Compare to multiple numbers

2005-05-16 Thread Wagner, David --- Senior Programmer Analyst --- WGO
[EMAIL PROTECTED] wrote:
> Why doesn't this work to check the  until it is one of the
> numbers "1 2 3 4 5" ?? I have tried multiple variations of this with
> different brackets ie. [ ] , and ( ) .
> 
> 
> 
> until($type_number == 1 .. 5 ){
> 
I know that you could use a character class [1-5] inconjunction with a 
regex:
$type_number =~ /^\s*[1-5]\s*$/ 
or you could predefine in a hash the valid inputs and check something 
like:

my %ValidInputs = qw ( 1 1 2 1 3 1 4 1 5 1);
my $type_number = '';

until($ValidInputs{$type_number}){

Now if there are spaces before or after, it will still not be right.

What you are really asking ( at least my my perspective in your 
statment is:
$type_number == 1 or 2 or 3 or 4 or  5

which under Perl is not valid.  You would have to tie the first part ( 
$type_number == ) with each or.  I know it would be nice, since Cobol can do 
this, why not Perl.  Maybe one of the Perl gurus can give us the why.

There are a couple of ways to try.

Wags ;)  ps Use 'use strict and use warnings' makes life much easier if you 
start off that way.  Just a thought.

> print "Enter the number that corresponds to the type of offense you
> would like a report for\n";
> 
> print "1. Virus\n2.Spam\n3.Hacking\n4.Copyright\n5.Child
> Pornography\n"; 
> 
> chomp($type_number = );
> 
> }
> 
> 
> 
> 
> 
> Chris Hood



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


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




Re: columnwise analysis

2005-05-16 Thread Aditi Gupta
hey Xavier,
thanks a lot.. i'm sure that's going to help..
if i have any problem applying the regex then i'll come back to the list:-)
thanks again
 aditi

 On 5/17/05, Xavier Noria <[EMAIL PROTECTED]> wrote: 
> 
> On May 14, 2005, at 19:47, Aditi Gupta wrote:
> 
> > there are actuaaly no fields specified.. i have strings in each row
> > (with intermittent hyphens) and i've to find which alphabet occurs
> > how many times in each column and then perform reg exp operations..
> > but i've never dealt with such columnwise analysis before and
> > haven't seen in books also so far.. which documentationshould i
> > refer for such problem..
> 
> From that description my guess is that we have:
> 
> my @cols = split /\s*-\s*/, $row;
> 
> If an "alphabet" can have a stringfied representation, a code for
> example, and if given a $col we imagine for the sake of this followup
> a function that guesses $col's alphabet code:
> 
> my $code = guess_alphabet($col);
> 
> then a possible approach would be:
> 
> my @counters = ();
> while (my $row = <$fh>) {
> my @cols = split /\s*-\s*/, $row;
> for (my $i = 0; $i < @cols; ++$i) {
> my $code = guess_alphabet($cols[$i]);
> ++$counters[$i]{$code};
> }
> }
> 
> That's to be taken as pseudocode (I wrote it just inline), and
> needing adjusts taking into account details of the actual problem to
> solve.
> 
> The main idea is that we have an array of counters called @counters.
> The ith element of @counters contains counters per alphabet
> corresponding to the ith column in the input file.
> 
> To distinguish counters per alphabet at column $i, we store a hashref
> at $counters[$i], whose keys are alphabet codes, and whose values are
> counters per alphabet. That is, $counters[$i]{$code} gives how many
> times alphabet with code $code has been seen in the $ith column.
> Alphabets not seen at column $i have no entry, but $counters[$i]
> {$code} would evaluate to undef without problem.
> 
> Does that help? Can you apply regexps as you need with that structure?
> 
> -- fxn
> 
> PS: Notice that we don't explicity create the hashref to be stored at
> $counters[$i], we directly write $counters[$i]{$code}. That's thanks
> to a nice feature of Perl called "autovivification" that creates
> structures on the fly for you.
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
>