Re: A "sub" question...

2005-12-30 Thread Adriano Ferreira
On 12/30/05, Robert Hicks <[EMAIL PROTECTED]> wrote:
> Note the leading underscore in the sub name. What does that mean? Is that
> like making it "private"?

Yes. But as a convention: that means: you sensible reader, don't you
try to rely on this function outside of this immediate realm of code.
But you can cheat as you like - at your risk.

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




Re: checking gzip files

2005-12-30 Thread Adriano Ferreira
On 12/30/05, Xavier Noria <[EMAIL PROTECTED]> wrote:
> Even if gzipped files have always more than 0 bytes, wouldn't it be
> true than all empty gzipped files have the same size, and that non-
> empty gzipped files are greater than that minimum? In this Mac that
> size seems to be 24 bytes.

Nope. Gzipped files have a header which may include filename.

$ touch foo
$ ls -l foo
-rw-r--r--  1 me mine 0 Dec 30  2005 foo
$ gzip foo
$ ls -l foo.gz
-rw-r--r--  1 me mine 24 Dec 30 18:04 foo.gz
$ touch foobar
$ ls -l foobar
-rw-r--r--  1 me mine 0 Dec 30  2005 foobar
$ gzip foobar
$ ls -l foobar.gz
-rw-r--r--  1 me mine 27 Dec 30 18:04 foobar.gz

Well - it looks like an empty gzipped file with a name takes C<21 +
length($name)> but that's not reliable since the header size may vary.

$ touch foo
$ ls -l foo
-rw-r--r--  1 me mine 0 Dec 30  2005 foo
$ gzip -n foo # omit name from header
$ ls -l foo.gz
-rw-r--r--  1 me mine 20 Dec 30  2005 foo.gz

To be true, in gzip file specifications, there is a field with the
size of the uncompressed data - but that's what
zlib/zcat/Compress::Zlib access for us to know the file is empty.

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




Re: Use of uninitialized value Error

2005-12-30 Thread Adriano Ferreira
On 12/30/05, David Gilden <[EMAIL PROTECTED]> wrote:
> In the Script below the line:  last if ($num >= 35)
> is giving me this error: Use of uninitialized value in int

That's not an error, but a warning. You will find that execution goes
after this.

> How do I avoid this error?
@files probably contain a name which does not match /(\d+)/. In this
case, $1 turns to be undef, and so happens with $num (because
int(undef) -> undef) up to the numeric comparison which (under -w)
emits the warning.

To avoid the warning, maybe you don't need to process such filenames

  ...
  $_ =~ /(\d+)/;
  next unless $1; # skip to the next item
  $num = int($1);
  ...

or you consider $num as 0 in this case, by replacing C<$num = int($1)>
with C<$num = int($1 || 0)

>
>
> my @files contains: Gambia001.tiff through Gambia100.tiff
>
> #!/usr/bin/perl -w
>
> my @files =<*>;
> $tmp= 1;
>
>
> for (@files){
> my $old = $_;
> $_ =~ /(\d+)/;
> $num = int($1);
> #$_ =~s/Gambia_Pa_Bobo_kuliyo_\d+/Gambia_Pa_Bobo_kuliyo_$tmp/i;
> print "$num\n";
> #$tmp++;
> last if ($num >= 35);
> # rename($old,$_);
> }

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




Re: How to improve speed of returning value from calling method on an array of objects?

2006-01-06 Thread Adriano Ferreira
On 1/6/06, Sai Tong <[EMAIL PROTECTED]> wrote:
> I have an array of many objects and I want to call a method on
> each of these objects and the save the returned values into an array:

> my @return_values;
> foreach my $retrievedObject (@array_of_objects) {
> push (@return_values , $retrievedObject->method );
> }

Maybe you can use C

   my @return_values = map { $_->method } @array_of_objects;

But that's not going to be fast (as well as the for construction) if
the repeated calls of C<$_->method> aren't fast enough (for your
purposes).

Adriano.

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




Re: The "@" symbol

2006-01-13 Thread Adriano Ferreira
A here document (like the one you wrote in your script between
"< wrote:
> trying to include the following code with the abc.pl script...
>
> the snippet works in an html/css environment
>
> print <
> 
> @import url("theta.css");
> @media print {
> body {background: white; color: black; font: 12pt Times,
> serif;}
> #noprnt {display: none !important;}
> }
> 
>
> EOF
>
> The "@" symbols are misread and thus this cause errors...  escaping the
> "@" symbols doesn't work
>
> anyone with a solution??
>
> Thanks
>
> Jerry
>
> --
> 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: The "@" symbol

2006-01-13 Thread Adriano Ferreira
On 1/13/06, Adriano Ferreira <[EMAIL PROTECTED]> wrote:
> It is in core documentation somewhere, even though I could not locate
> it right now.

Here it is: try C in the section "Regexp Quote-Like
Operators", search for the item <http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: the 'tail' problem

2006-01-14 Thread Adriano Ferreira
Jeff,

Maybe all you have to do is make some adjustments to the pipe you're
opening. Besides the well known "-f" switch, some tail's (like gnu
tail) support "-F" which means a file is followed by its name and the
opening is retried from time to time. From "man tail" (GNU):

   -F same as --follow=name --retry

  With  --follow  (-f),  tail  defaults to following the file descriptor,
  which means that even if a tail'ed file is renamed, tail will  continue
  to  track  its  end.   This  default behavior is not desirable when you
  really want to track the actual name of the file, not the file descrip-
  tor (e.g., log rotation).  Use --follow=name in that case.  That causes
  tail to track the named file by reopening it periodically to see if  it
  has been removed and recreated by some other program.

If you found it works for symlinks, all you have to do is use

> open (TAIL,"tail -F $log|") or die "can't open pipe:$!";

Regards,
Adriano Ferreira.

On 1/14/06, Jeff Pang <[EMAIL PROTECTED]> wrote:
> I have a log file which is a symbol link to the real logfile,shown as 
> following:

> I have to access this file in perl script with unix 'tail -f' command.Part of 
> the code is below:
>
> open (TAIL,"tail -f $log|") or die "can't open pipe:$!";

> This script is a daemon script which run permanently.There is no problem when 
> in the same day.But when the date changed,the symbol link file will point to 
> another real logfile automatically (which decided by other application 
> program),such as:
>
[snip]
>
> How can I adjust this problem?Thanks a lot.

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




Re: the 'tail' problem

2006-01-14 Thread Adriano Ferreira
On 1/14/06, Jeff Pang <[EMAIL PROTECTED]> wrote:
> Thanks for Adriano.I have tried the way that mentioned by you,and  found it's 
> no use for me.
> should the '-F' option  have no effect for symlinks maybe?
>

Well, that way would be easier if it worked. But I think with some
extra logic you can do it with help of the Perl builtin "readlink",
which is able to give you the filename the symbolic link points to.
Probably something can be written that checks to see if the link
changed or not.

Surely there's a CPAN module out there to help you do this. I also
made a few hasty tests, and if you got hard links rather symbolic
ones, it looks like "tail -F" would do the magic without hassle.

Cheers,
Adriano.

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




Re: regarding panic error message.

2006-01-31 Thread Adriano Ferreira
On 1/31/06, Nischitha <[EMAIL PROTECTED]> wrote:
>   Can any one please explain me what are these panic error message. When will 
> they be generated.

Panic error messages are usually triggered by Perl core code. I have
seen them when some piece of the interpreter (like the parser)
produced an inconsistent state which the next piece (for example, the
optimizer) can't handle. So it panics, instead of going further - and
possibly generate a SEGV. I think the general rule is that Perl should
not panic, but it does sometimes. Some panic errors are guards that
were coded to avoid issues that caused SEGV, but which were not
resolved yet. I think you may direct samples that caused panic to the
perl5-porters where you may learn this is a known issue, when it is
expected to be fixed, which are the workarounds or where this will be
appropriately filed and enter the queue to be fixed when someone got
the tuits to do it.

Regards,
Adriano Ferreira.

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




Re: problem with whitespace not splitting on split.

2006-04-26 Thread Adriano Ferreira
On 4/26/06, Rance Hall <[EMAIL PROTECTED]> wrote:
> @domain = split(' ',$domainlist);

This usage of split only splits at spaces. For example, if $domaintlist contains
'a b c', you will get ('a', 'b', 'c'). It has nothing to do with other
kinds of spaces.

If you meant

@domain = split /\s+/, $domanlist;

then you got it right.

> what happens is that the whitespace that is in the string is stripped
> out and only one array element is returned after the split even though
> there should have been several.

Maybe you're trying to see the result in @domain like this

print @domain

and print in this case uses no delimiter between the array elements.
If you do something like

print "@domain" # will use ' ' between array elements

print join "-", @domain # will use '-' between array elements

maybe you will discover it is working, but you just didn't choose well
how to show it to you.

Best regards,
Adriano

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




<    1   2