Re: MSSQL server 200 , cgi in perl

2004-11-18 Thread Ricardo SIGNES
* Chandrakant Reddy <[EMAIL PROTECTED]> [2004-11-18T03:20:49]
>   Any one tried to connect Mssql server from perl which is on Solaris Machine.
>   I installed  Class::DBI::MSSQL  using CPAN  and also go through the
> perldoc Class::DBI::MSSQL but didn't get much.

Are you actually using Class::DBI?  Do you know what Class::DBI?  I
don't suggest using Class::DBI(::MSSQL) until you know you can connect
normally.  

By "normally," I mean with the standard Perl database interface, DBI.
To connect to MSSQL with DBI, you'll want to use the DBD::ODBC or
DBD::ADO drivers, both on the CPAN.  ADO requires Win32.  ODBC requires an ODBC 
system.  On Win32, a connection to MSSQL via ODBC might look like this:

my $dbh = DBI->connect(
 'dbi:ODBC:driver={SQL 
Server};server=mydbserver;databasename=northwind;Trusted_Connection=no',
 $user,
 $password
)

FWIW, Class::DBI::MSSQL is meant to be used with ODBC.

I can offer no advice for using ODBC from a non-Win32 system.

>   I need one sample script  and also  what are the  api's available in
> perl to connect MSSQL server database.

Try googling for "dbi tutorial"

-- 
rjbs


pgpobEJNesq3S.pgp
Description: PGP signature


Re: perl template

2005-01-05 Thread Ricardo SIGNES
* "Anish Kumar K." <[EMAIL PROTECTED]> [2005-01-05T05:52:16]
> I use a perl template and getting this error
> 
> my $templateFile="\home\anish\temp\client.html";
> $template->process($templateFile, \%inputVariables) || die "Template process 
> failed: ", $template->error(), "\
> n";
> 
> absolute paths are not allowed (set ABSOLUTE option)
> 
> Please help me

I think the error message is being pretty darn helpful on its own.

First of all, are you sure you don't mean
"/home/anish/temp/client.html"?

Template Toolkit is complaining that you shouldn't use absolute paths --
that is, filenames that start at the root directory.  It wants relative
paths -- filenames that start "here" like this: "temp/client.html"

TT2 would then look through all the TEMPLATE_PATH directories for that
template.  If you want absolute paths to be allowed, set the ABSOLUTE
option.

$template = Template->new( ... ABSOLUTE => 1 ... )

Consult the Template manual.

-- 
rjbs


pgpnjsliTz9UL.pgp
Description: PGP signature


Re: Perl Catalog

2005-02-14 Thread Ricardo SIGNES
* hengky <[EMAIL PROTECTED]> [2005-02-13T19:05:25]
>  ---
> | id_cat  | nama_category   | id_parent |
>  - - ---
> | 001 | Computer| TLCAT |
> | 002 | Motherboard | 001   |

Why "TLCAT" and not NULL?  Then you could use a proper numeric type.

> while(@DataCat = $sth->fetchrow_array() ) {
> [...]
> ONE:
> while() {
>   [...]
>   while(@DataCat2 = $sth2->fetchrow_array() ) {
>   [...]
>  }
>}
>  }

Not pictured: "last ONE:"  You don't need a colon there.  The colon goes
where the label is declared, not when you mention it.  "last ONE;" would
have worked.

That said, what you want here is a recursive sub.

  sub full_name_for {
my ($id) = @_;
my ($name, $parent) = $dbh->selectrow_array(
  "SELECT name, parent FROM categories WHERE id = ?",
  undef
  $id
);
return $parent ? $name : (full_name_for($parent) . "/$name")
  }

So: given an id of a category:
  1. looks up its name and parent
  2. if it has no parent, return the name
  3. if it has a parent, return the parent's name followed by the
 category name
  4. to determine the parent's name, go to step one

Eventually, if you have no loops, you will get to a top level element
and stop recursing.  I will leave loop detection up to you.

-- 
rjbs


pgpjbApbHjdA1.pgp
Description: PGP signature


Re: Getting the content of a .doc file under Unix

2005-02-14 Thread Ricardo SIGNES
* Octavian Rasnita <[EMAIL PROTECTED]> [2005-02-14T08:46:22]
> Does anyone how to get the text from a .doc file under Unix?
> I would like to make a program which is portable and also work under Linux,
> not only under Windows, and I think Win32::OLE won't work under Linux.

google for "catdoc" and "antiword"

Win32::OLE is for automating COM/OLE programs, which means Word must be
installed, among other things.

-- 
rjbs


pgpgyMhXhz1v5.pgp
Description: PGP signature


Re: linking perl two programms

2005-02-15 Thread Ricardo SIGNES
* "E.Horn" <[EMAIL PROTECTED]> [2005-02-15T07:11:59]
> Perhaps someone can help me!
> Is there the possibility to link one programm to another perl
> programm?so that on click the link and the next programm starts?
> Example:
>  print "";
>  print " Hello";
>   print "";
>  print "";
>  print "Suche:$search";
>  print ""; ???

You need to get a basic grounding in CGI programs.

http://users.easystreet.com/ovid/cgi_course/

That's a pretty decent tutorial, and I'm afraid you'll find your program
nearly verbatim as "what your first CGI program should NOT be."

If your program is linked to as "foo.pl" and your server knows to run
it, and you want some link to run and return the result of some other
script, bar.pl, you just need to link to it.  Assuming your paths are
correct in the last line of your given code, the problem is your
quoting.  This would be better:

  print '';

...but I still suggest you read Ovid's CGI Course.

-- 
rjbs


pgp2NjzmkPDW5.pgp
Description: PGP signature


Re: Case-operator

2005-02-28 Thread Ricardo SIGNES
* Vladimir D Belousov <[EMAIL PROTECTED]> [2005-02-28T07:01:02]
> Is in the perl operator like C/C++ 'case' ?

I believe you are asking: Is there Perl equivalent to C's switch/case
construct?

Not exactly.

To see the official Perl documentation on this, run: perldoc -q case

This will search the FAQs for the keyword "case" and in the second
question you'll get some information, and a pointer to another bit of
Perl documentation, the "perlsyn" page.

A common idiom is something like this:

  SWITCH: for ($value) {
/regex/and do { something($x); last SWITCH };
/regex/and do { something($y); last SWITCH };
(! $value) and do { something(0);  last SWITCH };

something($default);
  }

The documentation mentions Switch, the module.  While Switch is neat, I
wouldn't suggest using it in production.

-- 
rjbs


pgpVyCErbsaer.pgp
Description: PGP signature


Re: Multiple file upload

2005-03-02 Thread Ricardo SIGNES
* Mallik <[EMAIL PROTECTED]> [2005-03-02T07:26:15]
> Anybody knows how to upload multiple files from a web page to server
> without using multiple file upload fields?

The file input selects one file, and that's that.

You could have the user first create an archive to upload, but then
you'd need to unarchive it...

-- 
rjbs


pgpNmzQumXdA0.pgp
Description: PGP signature


Re: Why don't I need a & to call a function?

2005-05-06 Thread Ricardo SIGNES
* Siegfried Heintze <[EMAIL PROTECTED]> [2005-05-06T01:02:59]
> I've been studying this sample code that someone gave to me in response to
> one of my earlier queries. Why is it not necessary to put a "&" in front of
> DBH in the statement DBH->prepare?
 
> sub DBH { [ ... ] }
> 
> my $sth = DBH->prepare ( qq { ... } );

Because, well... it isn't!  In Perl 5, it is more useful to start with
the assumption that sub calls don't need to be prefix with & and then
find the exceptions, rather than the reverse.  Do you have a specific
reason to think that a & should be required here?

Here are some of the reasons you'd need &:

The subroutine has a prototype, and you want to circumvent it.
sub foo($$) { ... }

&foo(1);

You want to pass @_ as the arguments to the called function.
sub foo { &bar; } # passes the arguments to foo to bar

You're calling a subroutine reference.
$foo = sub { ... };
&$foo;

If you don't need to use the &, avoid it.  It's noisy.

-- 
rjbs


pgpJ6JjIWrO52.pgp
Description: PGP signature


Re: The last element

2005-05-07 Thread Ricardo SIGNES
* amr <[EMAIL PROTECTED]> [2005-05-07T19:45:56]
> Thanks it was very useful.
> Now, I need to do the same with sorted hash array. Can I?

"sorted hash array" is not clear, to me.  Do you mean you've done this:
sort keys %hash
?

If so, just reverse the sort and use the first element, or assign to an
array and use element -1 as in previous mails.

-- 
rjbs


pgp5wYCngXgrN.pgp
Description: PGP signature


Re: how to check the particular perl module is installed or not on unix machine...............

2005-10-01 Thread Ricardo SIGNES
* [EMAIL PROTECTED] [2005-10-01T09:27:16]
> Perlers...
> Could u plz help me how to check in unis machine whether a particular perl 
> module is installed on unix machine or not

(Here on perl-beginners, I think non-LOL English is the preferred
dialect.)

The traditional test for "Do I have XYZ:ABC installed?" is:

perl -MXYZ::ABE -e1

That is about equivalent to running this perl program:

#!/usr/bin/perl
use XYZ::ABE;
1;

If you get an error like, "Couldn't find XYZ/ABE.pm in @INC..." you
don't have the module installed in your inclusion path.

-- 
rjbs


pgp21cvDcfxTw.pgp
Description: PGP signature


Re: statistics of text

2005-11-02 Thread Ricardo SIGNES
* "Ing. Branislav Gerzo" <[EMAIL PROTECTED]> [2005-11-02T08:52:39]
> I have quite interesting work. Example:

I wish /I/ could find this sort of work interesting!  Or profitable.

> Now, I have to find all 2 words sentences with their sums in the list.
> For example for this list it could be (without reporting lines):
> "foo bar" - 5 times (lines: 3, 4, 5, 7, 8)
> "bar bar" - 2 times (lines: 4, 6)
> "bar foo" - 3 times (lines: 5, 6, 8)
> "foo foo" - 1 time (line: 7)
> "foob bar" - 1 time (line: 9)
> "foo bars" - 1 time (line: 10)

 my %occurances; # we'll put occurances here
 
 while (<>) {# get each line of argument files (or sdin)
chomp;# eliminate the newline
my @words = split /\s+/;  # break into words on spaces
next if @words != 2;  # we only care about two-word lines
push @{$occurances{"@words"}}, $.; # add current line ($.) to list of
   # lines where we saw these words
 }

 for my $words (keys %occurances) {  # for each found paid
 my @lines = @{ $occurances{$words} }; # get the occurances
   print
 "$words - seen ",   # we saw this paid...
 scalar @lines,  # as many times as there are occurances
 " times: (lines: ", join(", ", @lines), ")\n"; # and then list 
lines
 }

-- 
rjbs


pgp8W7sbmGZJU.pgp
Description: PGP signature


Re: What is "shift" ?

2005-11-13 Thread Ricardo SIGNES
* Dylan Stamat <[EMAIL PROTECTED]> [2005-11-13T22:19:17]
> No, not the routine that deals with Arrays !

If you don't know what it is, why are you making assumptions, or telling
us what it isn't?  If you don't know, don't assume!

> I see code like the following, everywhere:
> my $coolvariable = shift;

Did you look at the documentation for shift?  The built-in functions are
well-documented in perldoc:

from the output of "perldoc -f shift"

  shift ARRAY
  shift   Shifts the first value of the array off and
returns it, shortening the array by 1 
and moving everything
down.  If there are no elements in the 
array, returns the
undefined value.  If ARRAY is omitted, 
shifts the @_ array
within the lexical scope of 
subroutines...

In other words, it IS the routine that deals with arrays.  The arguments
to a subroutine are available in the @_ array.

sub do_something_cool {
my $coolvariable = shift;
go_under($coolvariable); # you're right, mark, that is cool
print "down under where the lights are $coolvariable\n";
}

If I call do_something_cool("low"), execution will move to the
do_something_cool sub, with @_ = ("low").  shift will take the argument
from the stack and put it in the newly-declared lexical.

It will do something, then print the line with "low" interpolated into
it.

-- 
rjbs


pgpWItKqzF672.pgp
Description: PGP signature


Re: Doubt

2005-12-11 Thread Ricardo SIGNES
* anand kumar <[EMAIL PROTECTED]> [2005-12-11T22:38:00]
>  I am new to perl .i have a doubt in analysing the following regex.
>(my $book = $ref_string) =~ s/\s*(\d+(?::\d+(?:-\d+(?::\d+)?)?)?)\Z//;
>
>   here i want to know the meaning of '?:'

Normally, something enclosed in parentheses would be "captured" for
later use.

For example:

  (my $altered_string = $string) =~ s/\A123(\d+)\z/321$1/;

This would change "1238302938" to "3218302938" by capturing the digits
after 123 into $1, which is later interpolated in the right-hand side of
the s/// expression.

?: inside the parentheses indicates that you don't want to capture.

  (my $altered_string = $string) =~ s/\A123(?:\d+)\z/321something/;

Here, since we don't care about the digits after 123, we can throw them
away, so we don't need to capture them.  For this reason, we use ?: to
say "group these together, but don't capture them.

There are many uses for this.  In the example you provided, it is
probably being done for the small optimization it provides.

-- 
rjbs


pgptyegtLuESK.pgp
Description: PGP signature


Re: What does this line of code say?

2006-01-11 Thread Ricardo SIGNES
* Bill Gradwohl <[EMAIL PROTECTED]> [2006-01-11T09:08:15]
> while ( ($k,$v) = each %father ) {
> push( @{ $children{$v} }, $k );
> }
> 
> It's the push line I'm having difficulty with. Here's what I understand:
> 
> The outermost {} can be removed to simplify it to : 
>   push( @$children{$v}, $k);

You understand incorrectly.

If it was  @{ $foo } you could simplify to @$foo, but you cannot
simplify what you see to what you said.

@{ $children{$v} } means:
  get the scalar stored in $children{$v} (which is an entry in
  %children) and dereference it as an array

In other words:

  my $entry = $children{$v};
  @$entry;

@$children{$v}, which you suggested, would mean:

  get the hash slice of all entries in the hash to which $children
  refers, containing the following keys: $v

In other words, with an only slight change in meaning:

  my $hashref = $children;
  my %hash = %$hashref;
  @hash{($v)};

-- 
rjbs


pgpLcFGLnrHgf.pgp
Description: PGP signature


Re: What does this line of code say?

2006-01-11 Thread Ricardo SIGNES
* Bill Gradwohl <[EMAIL PROTECTED]> [2006-01-11T10:07:10]
> On Wed, 2006-01-11 at 09:25 -0500, Ricardo SIGNES wrote:
> > @{ $children{$v} } means:
> >   get the scalar stored in $children{$v} (which is an entry in
> >   %children) and dereference it as an array
> > In other words:
> >   my $entry = $children{$v};
> >   @$entry;
> 
> First, Thank You for your reply.

You're quite welcome!

> I thought about that as a possibility, but rejected it because I never
> saw the %children hash ever get initialized with even a single key/value
> pair. As far as I can tell, $children{anything at all} is undef. I know
> that's incorrect since the code works, but I can't see how it works. I
> understand that autovivification is creating things on the fly as
> needed, but see no mechanism to supply a key/value pair.

  use strict;
  use warnings;

  use Data::Dump::Streamer;

  my %children;

  push @{ $children{isaac} }, qw(jacob esau);

  Dump(\%children); 

This will output, more or less: $HASH1 = { isaac => [ 'jacob', 'esau' ] };  

> The push is extracting a value to be used as an array reference, but to
> extract a value, one must be there to begin with and I can't see how a
> value was ever supplied.

It is not extracting a value, it is asserting that a value, specifically an
array reference, exists.  Since there is nothing to prevent that from becoming
true, it does.  The author says, "let there be an arrayref," and there is, and
it is good.

This, however, would not be good:

  my %children = ( joe => '' );
  push @{ $children{joe} }, qw(betty veronica);

You see, undef can be used as an array ref -- it becomes [].  "" can't be used
as an array reference, and neither can a lot of things -- most, in fact.  Only
undef and an array reference can be treated as an array reference, and once
you treat undef like an array reference by pushing to it, it ceases to be
undef.

Autovivification is a great thing, but it does sometimes cause a bit of
consternation.  Good luck!

-- 
rjbs


pgpGvfH71N8Wg.pgp
Description: PGP signature


Re: Generation of method names

2006-02-26 Thread Ricardo SIGNES
* Klaus Jantzen <[EMAIL PROTECTED]> [2006-02-24T16:09:10]
> After the DB-connect I would like to automatically generate the name of the
> appropriate set-method in order to reduce the typing :) :

I believe that you meant that while the methods already exist, you just want to
call the methods by generated name -- right?  Your example bears this out:

> while (my $hrRes = $sth->fetchrow_hashref)
> {
> foreach (@fields)
>   {
>   $self->"set".$_($hrRes->{$_});
>   # resulting in e.g. $self->setDate($hrRes->{'Date'}) or
>   #   $self->setAmount($hrRes->{'Amount'})
>   }
> }

You can call methods by generated name, but you must put the name in a scalar
first.  You can't say:

  my $value = $object->"method" . "_etc";

You can say:

  my $method_name = "method" . "_etc";
  my $value = $object->$method_name;

Does that clear this up?

-- 
rjbs


pgp1m5oOcSJd4.pgp
Description: PGP signature


Re: using "our" across blocks

2006-05-02 Thread Ricardo SIGNES
* Anthony Ettinger <[EMAIL PROTECTED]> [2006-05-02T15:04:53]
> I want to double-check that it is correct to use "our" to import globals.
> 
> BEGIN {
>our $foo = 'foo';
> }
> 
> sub something {
>our $foo;
>our $bar;
> }
> [ ... ] 
> Is this the correct way to import globals?

Yes, if by "globals" you mean "globally accessibly, and therefore screw-up-able
from anywhere."

You'd probably be better off, in most cases, with lexicals

  my $foo = 'foo';  # or: my $foo; BEGIN { $foo = 'foo' }
  sub something {
...
  }

That way, people ourside your file can't access your private data.

-- 
rjbs


signature.asc
Description: Digital signature


Re: Grep a variable

2006-05-19 Thread Ricardo SIGNES
* Umesh T G <[EMAIL PROTECTED]> [2006-05-19T08:54:17]
> I am trying to grep a variable from a scalar value. Here is the example 
> below.
> 
> $var = "mydisk";
> $line = "mydisk is bad";
> if (grep/\$var/,$line) {
>print "disk is not bad";
> }

The simplest answer, already given, is that you should lose the backslash
before the $ in $var, but I think that's not helpful enough.

You're using the "grep EXPR, LIST" form of grep, which evaluates an expression
for each element of the LIST and returns either the number of things for which
it was true, or those things for which it was true.  I suggest never using this
form.  Instead, use the "grep BLOCK LIST" form, which replaces that expression
with a little snippet of code.  This is more flexible and often clearer.

You could rewrite your line as:  if (grep { /$var/ } $line) {

Then again, since $var isn't a regular expression, you could just check whether
the contents of $var occur in $line:

  if (grep { index($_, $var) > -1 } $line) {

That says, "if any of the given elements have the contents of $var in them
somewhere..."  That way you can avoid using the regular expression engine,
which might be slower or do things you didn't expect, depending on the contents
of $var.

Then again, since you're only using one thing, not a list, you could skip grep
entirely!

  if (index($line, $var) > -1) {

-- 
rjbs


signature.asc
Description: Digital signature


Re: GnuPG module help?

2006-05-24 Thread Ricardo SIGNES
* "Dr.Ruud" <[EMAIL PROTECTED]> [2006-05-24T08:13:15]
> "Angus" schreef:
> > my @encrypted = $gpg->encrypt ('$data', '[EMAIL PROTECTED]');
> 
> 
> That call doesn't seem right to me:
> http://search.cpan.org/~frajulac/GnuPG-0.09/
> 
> The protoptype in GnuPG.pm: encrypt($%)

On one hand, you're quite right.  Looking at the code shows that the argument
to the method should be a hash.

On the other hand, the author of GnuPG is confused.  Prototypes are entirely
ignored when calling methods.  He could make the prototype (@$$&;@) and nothing
would care.

-- 
rjbs


signature.asc
Description: Digital signature


Re: Test::Pod::Coverage

2006-06-03 Thread Ricardo SIGNES
* Ken Foskey <[EMAIL PROTECTED]> [2006-06-03T06:53:35]
> #!/usr/bin/perl
> #  Ensure POD is set up correctly.
> use Test::More;
> eval "use Test::Pod 1.00";
> plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
> all_pod_files_ok( map( glob( "*.pm" ), s/.pm$//) );

Your map doesn't make any sense.  It says:

  for each element resulting from replacing .pm with nothing at the end of the
  topic:
return all files ending in .pm

I'm guessing that $_ is not defined.  You would have gotten a warning if you
were using strict and warnings.  This is why you should always use strict and
warnings:  it cuts the latency on help responses from an hour to a second or
so.

Maybe you meant this:

  all_pod_files_ok( map { s/.pm$//; $_ } glob("*.pm") );

That doesn't make sense, either.  all_pod_files_ok wants filenames, not
filenames without extensions.  You probably want:

  all_pod_files_ok(glob("*.pm"));

I've almost never needed to use anything more than:

  all_pod_files_ok():

That finds your perl modules in lib or blib, which is where they should be in a
standard dist.

-- 
rjbs


signature.asc
Description: Digital signature


Re: Yet another OO question

2006-06-08 Thread Ricardo SIGNES
* Graeme McLaren <[EMAIL PROTECTED]> [2006-06-08T05:44:05]
> Hi all, I've just been reading a bit about accessor get/set methods.  I 
> have a method:
> 
> sub even{
>my $self = shift;
>my $even   = shift;
> 
>$self->{_even} = $even if defined($even);
>return $self->{_even};
> }
> 
> 
> This basically does what a get and set method would do.  So why would I 
> need a set/get methods?  This value is passed to the object like so:

It's a question of style, largely.  Some people prefer their code to be
very clear about whether your getting or setting.  Using explicit set and get
methods can also help prevent bugs; you won't accidentally make a read-only
value writeable, because you will avoid writing a set_ro_value method -- if you
only have a get-and-set ro_value method, you might forget to special-case it to
be get-only.

Also, you'd probably avoid bugs like the one you introduced above.  What
happens if I want to clear the even value?

  $obj->even(undef);

This does not affect the value; I can't undef even.

You probably wanted:

  sub even {
my $self = shift;

return $self->{even} unless @_;
return $self->{even} = shift @_;
  }

-- 
rjbs


signature.asc
Description: Digital signature


Re: recusrive listing

2006-08-18 Thread Ricardo SIGNES
* "Smith, Derek" <[EMAIL PROTECTED]> [2006-08-17T10:52:16]
> What module would be ideal for getting a recursive listing into an array
> or hash?

Your code, below, makes it look like you really mean "for getting a recursive
directory listing."

> I was looking at IO::All

Is that a question?  Do multiple question marks convert into a period or
something?

Here's a crappy little directory lister I wrote once:

  http://rjbs.manxome.org/hacks/perl/tree

You could pretty easily turn that into a hash-builder.  Instead of passing in
an indent level, just pass in the directory name.  Instead of printing, return
a hashref.  So, for this:

  a/
  a/b.txt
  a/c.txt
  a/d/
  a/d/e.txt

You could end up with:

  { a => [ b.txt c.txt { d => [ e.txt ] } ] }

I've attached an example.

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

sub recursedir {
  my $dir = shift;
  my $hashref  = shift || {};

  die "error: $dir is not a directory\n" unless -d $dir;

  my @contents;

  my ($dname) = $dir =~ /([^\/]+)$/;

  foreach my $d (glob("$dir/*")) {
my ($fname) = $d =~ /([^\/]+)$/;

if (-d $d and not -l $d) {
  push @contents, recursedir("$d");
} else {
  push @contents, $fname;
}
  }
  
  return { $dname => [EMAIL PROTECTED] };
}

use Data::Dumper;
print Dumper( recursedir($ARGV[0] || '.') );


signature.asc
Description: Digital signature


Re: recusrive listing

2006-08-18 Thread Ricardo SIGNES
* "Smith, Derek" <[EMAIL PROTECTED]> [2006-08-18T09:30:54]
> No period conversion. Typically multiple ??? marks in the English
> language has inherited dual meanings: 1) a question and 2) thinking out
> loud wanting feedback.

Actually, they're typically considered wrong, and to be avoided, which is what
I was trying to remind you. ;)

> IO::All combines all of the best Perl IO modules into a single nifty
> object oriented interface to greatly simplify your everyday Perl IO
> idioms. It exports a single function called io, which returns a new
> IO::All object. And that object can do it all!

I know what IO::All is.  I nearly never use it, as it is nearly always too
clever and/or too much for me.

The code I supplied used just core Perl, and didn't need to get everything up
front, because it recursed down through directories.  I think this is the
better solution.  Is there a reason that a solution like this does not meet
your needs?

I think your need is: "I want a data structure that represents a directory
tree."  Maybe I am wrong..?

-- 
rjbs


signature.asc
Description: Digital signature


Re: log and ln formular in perl

2006-08-20 Thread Ricardo SIGNES
* chen li <[EMAIL PROTECTED]> [2006-08-20T07:18:59]
> I want to get the value 2 out of log based on 10 or
> natural number e (the result is 0.301 and 0.609,
> respectively). What are the formular for these two
> caulculation and how can I find more about math stuff
> in perldoc?

Perl has a natural log function built in.  It's called "log" and you can read
about it by running:  perldoc -f log

"log 2" will return 0.93147180559945, which is he natural log of 2.  To compute
a log of another base, you can take ((log $n) / (log $base)), so to get 2 log
10, ((log 2) / (log 10)), which gives you 0.301029995663981.

-- 
rjbs


signature.asc
Description: Digital signature


Re: Non-technical question

2006-09-20 Thread Ricardo SIGNES
* Mathew <[EMAIL PROTECTED]> [2006-09-20T19:29:53]
> I'm curious how to pronounce various built-in variables in perl.  Like
> $_ or [EMAIL PROTECTED]  Having never heard it spoken and only seeing it in 
> print,
> I've taken to calling it "dunder" (Dollar + Underscore).  Granted, the
> way I pronounce it has no impact on how my or anyone else's scripts run.

Good question.  Here are some common pronunciations:

  $_ - "it" or "the topic"
   foreach (@line) { chomp $_; };  # for each line, chomp it
  $! - "the error code" or "buck bang"
  $@ - "the exception" or "buck at" or "the error"
  @_ - "the stack" or "at under"

Many vars can be called by their English.pm name.

  $_ - "arg" -- I've never heard that
  $! - "errno" or "error number"
  $@ - "eval error" -- I'm not sure I've ever heard that
  $$ - "pid" (or "buck buck")
  $? - "child error" (I have never heard "buck hook")
  $, - OFS
  $\ - ORS
  $/ - RS
  $< and $> and $( and $) - uid, euid, etc
  $0 - "dollar zero"

Lots of the funny ones are rarely used enough, or their pronunciation is short
enough, that you just say them the way you would if you knew nothing about
perl:

  @ARGV - "argv"
  @INC  - "ink"
  %INC  - "percent ink"
  $;- "dollar semicolon'

> I've just been curious about what would, I guess, be considered the
> official pronunciation.  How would Larry pronounce it?

Nothing would.  Perl does not have an office.

-- 
rjbs

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




Re: scalar in array name?

2006-10-06 Thread Ricardo SIGNES
* Kenton Brede <[EMAIL PROTECTED]> [2006-10-06T11:38:49]
> I've done some searching and can't find an answer to this.  I'd like
> to use a scalar variable in an array name.  Something like "@$scalar"
> I've tried different permutations like "[EMAIL PROTECTED]", "@"$scalar""
> "@\$scalar" and none of them work.

What you're talking about is a symbolic reference.  The canonical reference for
why /not/ to do this is here:

  http://perl.plover.com/varvarname.html

> my $first_arg = "$ARGV[0]";
> my @list = ("all", "rhel");
> my @rhel = ("server1", "server3", "server4");
> my @all = ("server2", "server5", server7");
> 
> foreach my $list_name (@list) {
>if ( $list_name eq $first_arg ) {
>print "@$first_arg";
>}
> }

Use a hash instead:

  my $first_arg = $ARGV[0];

  my %group = (
rhel => [ 'server1', 'server3', 'server4' ],
all  => [ 'server2', 'server5', 'server7' ],
  );

  my @servers = @{ $group{ $first_arg } };
  print "@servers";

-- 
rjbs

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




Re: use strict and local variables

2006-10-16 Thread Ricardo SIGNES
* Raphael Brunner <[EMAIL PROTECTED]> [2006-10-16T08:38:00]
> But, my problem is, i must see this variable after the call of the sub.
> I'm sorry for the first example, it was inaccurate. But this is ok (I
> think) :) (because I have a lot of variables, which I must change in the
> sub, I want to define they as "global" inside my parent-routine (in the
> example: the programm, but by me: the parent-sub)).

So, pass in a reference to it.

Instead of:
> my $var = 20;
> 
> print "before: $var\n";
> &routine;
> print "after: $var\n";
> exit;
> 
> 
> sub routine {
>   $var += 1;
> }

Write:

  my $var = 20;
  print "before: $var\n";
  routine(\$var);
  print "after: $var\n";

  sub routine {
my ($input_ref) = @_;

$$input_ref += 1;
  }

Consult "perldoc perlreftut" for more.

-- 
rjbs

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




Re: How to Create a hash using SQL 2000

2003-12-16 Thread Ricardo SIGNES
* [EMAIL PROTECTED] [2003-12-16T07:21:19]
> I am using activestate version 5.8 on XP with DBI 1.38. I am trying to
> return values into an associative array so that I don't keep needing to
> connect to the database. I am new to perl and DBI is looking like rocket
> science. The code below has been gleaned from the Internet so I am not
> completely sure what is going on.
> [...]
> while (my $opi = $sth->fetchrow_hashref){
>   my %queue = $opi
> };

I believe this is your problem, not the other bits.
$sth->fetchrow_hashref will return a reference to a hash.  So, now $opi
is { col1 => val1, col2 => val2 } and so on.

You're assigning that to %queue, which is a hash that should have pairs
put into it.  Do you have strict and warnings on? ("use strict" and "use
warnings" at the top of your script.)  If so, you should see a message
about assinging an odd number of elements to a hash.  Even if you said:
%queue = ( 1 => $opi ) you'd be overwriting the element in your hash
every time.  

I suggest you do one of two things:

(a) use $dbh->selectall_hashref, which will return a hashref (keyed off
the column you indicate) of all the rows returned by the select.  So,
you could say
$queue = $dbh->selectall_hashref($sth);
print $queue->{$key}{$column};

(b) make %queue an array; if it's really a queue (and you're going to be
shifting work off the bottom) an array is more natural.  Then the loop
would read:
while ($sth->fetchrow_hashref) {
push @queue, $_;
}

(I believe this look should work now.  I think there's a caveat in the
DBI docs that someday fetchrow_hashref may return the same hashref with
new values every time.)

> IMPORTANT NOTICE  This email (including any attachments) is meant only
> for the intended recipient.

It would be nice if you could not send this disclaimer.  I realize that
might not be an options.

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: What would be the best data structure to keep these values

2003-12-16 Thread Ricardo SIGNES
* "Hemond, Steve" <[EMAIL PROTECTED]> [2003-12-16T10:13:31]
> I want trap the results of 'ps -ef' command.
> 
> I first trap the results by splitting the results in scalar values
> such as $uid $pid $ppid $stime, etc...
> 
> I would like, for each line returned, to hold these values in an
> array, so that, for each uid, I could return its corresponding pid,
> ppid, stime, cmd, etc.
> 
> What would be the best data structure to use? An hash table in an
> array? ...

The answer really really depends on what you want to do with the data.
If you just want to print it back out, an array of arrayrefs is
simplest.  If you want to query specific fields line-by-line, an array
of hashrefs might be best.  If you want to look things up by pid, a hash
of hashrefs might be best.

In order, those would be something like:

# LOL - list of lists
foreach $line (@ps_results) { push @lines, [ split /\s+/, $line ] }

# LOH - list of hashes
foreach $line (@ps_results) { 
@results{uid pid stime} = split /\s+/, $line; # this line is pseudo
push @lines, \%results;
}

# HOH - hash of hashes
foreach $line (@ps_results) {
@results{uid pid stime} = split /\s+/, $line; # this line is pseudo
%lines{$results->{pid}} = \%results;
}

I'd probably use a HOH, because accessing the data would be easy to
write and because *I'd* probably only be /reading/ the data if I thought
I'd later need to access it by pid and field name.

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: alternating loop

2003-12-18 Thread Ricardo SIGNES
* Mike Blezien <[EMAIL PROTECTED]> [2003-12-18T18:48:23]
> been trying to come up with a way, while going through a loop to
> alternate a table cell color 

I always do something more like:

my $i;
while (<>) {
print " ... \n"
}

The benefit here is that someday I can replace the 2 with 3 and have
three behaviors.  Yes, that's a minor benefit.

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: RegEx Troubles

2003-12-19 Thread Ricardo SIGNES
* Jeremy Mann <[EMAIL PROTECTED]> [2003-12-19T13:47:26]
> Given this in $_
> Most popular title searches: HREF="/title/tt0244365/">"Enterprise" (2001)"
> 
> why would this regex not put digits in $1 ?
> 
> $data2 =~ /popular title searches:<\/p> HREF=\"\/title\/tt(\d*)\/\">/

This code:
$data2 = 'Most popular title searches:"Enterprise" (2001)';

$data2 =~ /popular title searches:<\/p>/;
print $1;

prints '0244365'.

Notice that I put the string into $data2, not $_.  A bare regex (/foo/)
would work on $_, but you're using the =~ operator to fit the regex to
$data2, so the value in $_ is irrelevant.  Perhaps you wanted:

($data2) = ($_ =~ /r(ege)x/); # assign $1 to $data2

Also, keep in mind that while // is the most common delimiter for a
regex, it can lead to readability problems.  If you're going to have a /
character in your regex, why not a different delimiter for the regex?
It'll save you from escaping the slashes.  So:

$data2 =~ m!popular title searches:!;

Also, you didn't need to escape the quotes in the regex, you could have:

$data2 =~ m!!;

I hope these pointers help.

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: Simple Perl code/syntax question

2004-01-23 Thread Ricardo SIGNES
* Luinrandir Hernsen <[EMAIL PROTECTED]> [2004-01-23T09:38:12]
> Hallo everyone and thank you for your previous help
> 
> in basic the code would be
> Select Case
> ...
> end select
> 
> how is this done in perl?

Well, this is a common question.  In fact, it's a frequently asked one
with an entry in the perlfaq.  This kind of construct is called, in many
languages, a switch.  You can see the FAQ's answer by running "perldoc
-q switch" or by looking for the switch/case question in perlfaq7.

Your example was specific, so I can give a specific answer or two:

for (1 .. 100)  {
  unless ($_ % 10) { 
print "divisible by ten\n";
  }
}

That's about what you said, right?  For every number from 1 to 100, do
something at the ten's.  Of course, someone more familiar with C (or
with the syntax of 'for') might say:

for (my $i = 1; $i <= 100; $i+=10) {
print "$i is divisible by ten!\n";
}

This skips a condition, incrementing $i by ten every time.

See, Perl was designed knowing that there are a whole lot of ways to use
a switch, and a whole lot of ways one might implement it specifically.
So, rather than canonize one, a single "switch" statement is left out.
The best thing to do is figure out how to solve the problem the best
way.

There does exist a module called Switch that will give you a switch/case
statement, but it's not really for production use.  It's a neat idea,
but isn't ready for prime time.

Does that answer your question?

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: perl editors

2004-01-30 Thread Ricardo SIGNES
* [EMAIL PROTECTED] [2004-01-30T12:55:38]
> Thank you, but I was hoping to have a editor compatible with Redhat and or 
> HP and or AIX that gives you a color coded interface, such when there is a 
> syntax error it color codes it in red.  If you have ever seen or used a VB 
> editor you know what I mean.  Currently I use vi all the time, does vim 
> have this color ability?

Vim will syntax highlight, by marking variables and regex and a few
other things like that.  It can't find syntax errors, although it may
help make some clear. 

Syntax errors in Perl are very hard to find without running perl.  "Only
perl can parse Perl."

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: Perl 6

2004-02-02 Thread Ricardo SIGNES
* Dan Brow <[EMAIL PROTECTED]> [2004-02-01T18:43:15]
> Any one know when perl 6 will be released for production use?

No, no one knows.  For production use, it is still years away.

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: terminal manipulation in Perl

2004-03-18 Thread Ricardo SIGNES
* Ohad Ohad <[EMAIL PROTECTED]> [2004-03-18T06:55:48]
> Hey,
> 
> How do I send the cursor to the begining of  current line?
> 
> I want to output a circular string and I want the string to start over on 
> the same line.

This isn't so much a function of Perl as a function of your terminal.
Naturally, there exist modules of code for interacting with the
terminal.

Term::Cap
  http://search.cpan.org/~jstowe/Term-Cap-1.08/

Curses::UI
  http://search.cpan.org/~marcus/Curses-UI-0.92/

Or just search the CPAN:
  http://search.cpan.org/search?query=term&mode=all

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: Perl from Terminal in OSX

2004-03-18 Thread Ricardo SIGNES
* B McKee <[EMAIL PROTECTED]> [2004-03-18T13:48:55]
> >here is what I am typing:
> >>perl -e  test.pl
> 
> Change to the directory you saved the script,
> make sure it's executable with
>   chmod +x test.pl
> then run it directly
>   ./test.pl

...or if you don't want to make the file +x, you can just run it like
this:

  [EMAIL PROTECTED]  perl test.pl

The -e switch tells perl to evaluate the text given to it as the script,
so it doesn't open the file and run that.  So you could do this:

  [EMAIL PROTECTED] perl -e 'print "Hello, sailor!\n"'

Also, there's some hard feelings about file names.  *.pl was the old
school Perl extension for libraries of code, which served roughly the
same purpose as *.pm files serve now.  Kinda.  It stands for Perl
Library.  If you aren't writing a library, some people (including me)
would suggest that the extension is incorrect.  On a unixy system, you
indicate that its a program with the +x bit and you indicate that it's
Perl with the shebang (#!/...) line.

Of course, on Win32, you need an extension.  Some people have suggested
.plx, but ActiveState has used .pl, which has made it become fairly
standard.

Ok, that's all.

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: How to add CPAN in PPM Repository

2004-03-22 Thread Ricardo SIGNES
* Mallik <[EMAIL PROTECTED]> [2004-03-20T09:11:17]
> To add CPAN into repository, I typed the below command
> 
> ppm> rep add "CPAN" http://search.cpan.org/

The CPAN is not a PPM repository.  This will never work.

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: why $a became 6 ?

2004-04-15 Thread Ricardo SIGNES
* Jayakumar Rajagopal <[EMAIL PROTECTED]> [2004-04-15T14:22:08]
> $a=100; $b=200;
> ($a=3 && $b=6 ) if ( 1 == 1 );
> print " $a   $b  \n";
> 
> Output : 6   6  
> 
> OR my syntax is wrong ? 
> regards,
> Jay

Your understanding of precedence is wrong.  You've effectively said
this:

  ($a = (3 && $b = 6)) if 1;

The value of (3 && $b = 6) is the value of the last evaluated bit, $b=6.

You have two options:

1.  say "($a=3 and $b=3)" instead, because the precedence level of 'and'
is different

2.  use parentheses so that you don't have to memorize precedence

I suggest 2, although learning precedence is good.

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: Perl::Optomizer

2004-05-13 Thread Ricardo SIGNES
* "JupiterHost.Net" <[EMAIL PROTECTED]> [2004-05-13T11:35:58]
> Bob Showalter wrote:
> >> for instance:
> >>   $newvariable = "$howdy";
> >> should be:
> >>   $newvariable = $howdy;
> >
> >That's not an appropriate optimization. Perl objects can overload
> >stringification.
> 
> Interesting...
> So when would that cause problems?

If $howdy is an object that returns "Hello!" when turned into a string,
then the first bit of code assigns "Hello!" to $newvariables.  The
second bit of code makes $newvariable a copy of $howdy.

> >> $str = CGI::header() . "hello" . $v;
> >>
> >>woudl become
> >> $str = CGI::header(),"hello", $v;
> >
> >That's not equivalent code at all.
> 
> I didn't think so but I read somewhere to use commas instead of 
> concatenation with periods. I always thought the commas was a  bit 
> different but if you print $str; they are the samem in each example.

Look at the prototype for C.  It takes a LIST, and those elements
are concatted together and printed.  (see "perldoc -f print")  The value
of $, is stuck between list elements, but it's usually empty.

So, C is mostly equivalent to C in
usual circumstances, but C<$foo = $bar, $baz> is wildly different from
C<$foo = $bar . $baz>;  the first sets foo to baz.  The second sets it
to bar and baz concatenated.

> I'm sure I have much to learn as far as the period/comma thing go :)

When in doubt, look in perldoc.  About comma, it says:

 Binary "," is the comma operator.  In scalar context it evaluates its
 left argument, throws that value away, then evaluates its right
 argument and returns that value.  This is just like C's comma operator.

> What I'm really looking for is a similar thing to Perl::Tidy that I can 
> run a script throught and have it make an "optomized" version.

You mean "optimized."  

> That would be complex but wouldn't it be cool?

I can't imagine wanting to use it; it would take time to run, and I
don't think I would trust it.  Perl is fast enough for me.  Better to
learn how to write fast-enough code to begin with, imho.

-- 
rjbs


pgp0.pgp
Description: PGP signature


Re: combining data from more than one file...

2004-05-17 Thread Ricardo SIGNES
* "Michael S. Robeson II" <[EMAIL PROTECTED]> [2004-05-17T07:47:57]
> I am having trouble with combining data from several files, and I can't  
> even figure out how to get started. So, I am NOT asking for any code  
> (though pseudo-code is ok) as I would like to try figuring this problem  
> out myself. So, if anyone can give me any references or hints that  
> would be great.

One way to solve this problem is to create a hash, in which the keys are
the animal names and the values are the sequences, possibly in an
arrayref, possibly just cat'd together.

So, something like:

  for each file
open the file
for every new animal found
  add all the non-blank lines to $sequences{animal}

Is that clear-ish?

-- 
rjbs


pgpytVlXabRaG.pgp
Description: PGP signature


Re: How get a special value of an arrayfield stored in an hash?

2004-05-24 Thread Ricardo SIGNES
* Bastian Angerstein <[EMAIL PROTECTED]> [2004-05-24T08:07:37]
> $index = 1
> $var = ${$myhash{mykey}}[$index];

$var = $myhash{mykey}[$index]
$var = $myhash{mykey}->[$index]

Either will do.

-- 
rjbs


pgpc308dwTSbR.pgp
Description: PGP signature


Re: The >> operator

2004-05-29 Thread Ricardo SIGNES
* gohaku <[EMAIL PROTECTED]> [2004-05-29T00:28:07]
> Hi all,
> I'm not sure if ">>" is an official operator in Perl but I have seen 
> ">>" used in conjunction with
> HTML code or Long Strings.
> a google search and perldoc doesn't return any useful information.
> I am looking for code examples that use ">>".

Operators are documented in the "perlop" page of the documentation.  Run
"perldoc perlop" at your shell.

Looking in there for ">>" will net this:

  Binary ">>" returns the value of its left argument shifted right by
  the number of bits specified by the right argument.  Arguments should
  be integers.  (See also "Integer Arithmetic".)

-- 
rjbs


pgpoQCLvaXMBd.pgp
Description: PGP signature


Re: perl POE

2004-07-07 Thread Ricardo SIGNES
* Anish Mehta <[EMAIL PROTECTED]> [2004-07-07T04:49:30]
> Does anyone knows about some good links on PERL POE, how it allows Perl
> code to make asynchronous, non-blocking I/O calls and handle those I/O
> calls on the basis of Event Driven model and Event Queues.

poe.perl.org

or, of course, the current front page article on perl.com:
http://www.perl.com/pub/a/2004/07/02/poeintro.html

-- 
rjbs


pgpiyRJ4ORS6N.pgp
Description: PGP signature


Re: using tr

2004-07-07 Thread Ricardo SIGNES
* Cinzia Sala <[EMAIL PROTECTED]> [2004-07-07T09:35:42]
> I would like to transform a string like :
> 
> MSDDIDWLHSRRGVCK
> 
> in a identical string, but with two spaces between each letter:
> 

You wouldn't use tr/// for this.  There are two simple ways:

 $string =~ s/(.)(?!\Z)/$1 /g;
 # replace any char /not/ followed by end-of-string with itself and a
 # space

or

 $string = join('  ', split('', $string));
 # split $string into individual characters
 # then rejoin them with two spaces between them

consult "perldoc -f split" and "perldoc -f join" for the latter one.

-- 
rjbs


pgpWAWiuSswoK.pgp
Description: PGP signature


Re: Counting characters in a thread

2004-07-09 Thread Ricardo SIGNES
* [EMAIL PROTECTED] [2004-07-09T07:20:57]
> How would I empty $string if it contained more than ten % characters? In 
> other words

$string = "" if split(/%/, $string) > 10;

-- 
rjbs


pgpO8nLAuJ7WJ.pgp
Description: PGP signature


Re: accessing each element

2004-08-16 Thread Ricardo SIGNES
* Mandar Rahurkar <[EMAIL PROTECTED]> [2004-08-16T17:32:28]
> Hi,
>I have a list ,
> $list=['orange','red','purple'];
> 
> How do I access each member of $list ? If this had been @list I cud have 
> done,
> 
> foreach(@list) {
>  print $_;
> }
> 
> How does it work for a scalar ?

You really, really need to read the "perlreftut" page, which you can see
by running "perldoc perlreftut" at your command prompt.

$arrayref = [ 1, 2, 3 ]; creates a reference to an array.  To get at its
members you can do this:

foreach (@$arrayref) { print }

or just:

  print $arrayref->[0];

Please read that document.  It will help you understand what's going on.

-- 
rjbs


pgpAs9pWq66Jx.pgp
Description: PGP signature


Re: CSV type data into hash?

2004-09-21 Thread Ricardo SIGNES
* Tim Musson <[EMAIL PROTECTED]> [2004-09-21T09:25:23]
> It looks something like this;
> Name,Location,Function,IPAddress
> uas123,123 street,Mail,10.11.12.13
> uas321,123 street,Mail,10.11.12.14

As is often the case, I suggest going to the CPAN and searching for CSV.
You'll find lots of relevent modules.

Of course, if you want to take care of this yourself, as an exercise,
consider something long the lines of the following:

open my $csv_file, '<', "filename.csv"
or die "couldn't open file!";
my @columns = split(/,/, <$csv_file>);
chomp $columns[-1];
my @rows;
while (<$csv_file>) {
chomp;
push @rows, {};
@[EMAIL PROTECTED] = split /,/;
}

So:
Read the first line and break it up on commas to get column names.
Chomp the newline from the last column name.
Keep reading line, chomping their newlines.
Add an empty hash to the end of the rows, then populate it, matching
column names to field positions.

That code is off-the-cuff, but should work, I think. :)  If not, or if
you want more information, just holler.

-- 
rjbs


pgpXoqWq0mKDt.pgp
Description: PGP signature


Re: How may anonymous tables?

2004-10-05 Thread Ricardo SIGNES
* adam <[EMAIL PROTECTED]> [2004-10-04T22:32:50]
> Here is the code:
> my $r1 = [1,2];
> my $r2 = [1,2];
> 
> How many anonymous arrays do we have now?
> One or two?
> This shows we have two arrays: print "$r1\n$r2\n";

Two.
 
> Is there any way to find out how the system is naming these arrays 
> internally?

It isn't naming them.  That's why they're called anonymous!

When you print the array, the number in parens identifies the reference
uniquely.

-- 
rjbs


pgpfgdlXtrob2.pgp
Description: PGP signature


Re: Perl - Bit Manipulation

2006-11-14 Thread Ricardo SIGNES
* "Randal L. Schwartz"  [2006-11-14T16:34:43]
> > "Rob" == Rob Dixon <[EMAIL PROTECTED]> writes:
> 
> Rob> This is indeed a documentation bug. perlop says, in full:
> Rob> ~ The "=>" operator is a synonym for the comma, but forces any word 
> (consisting
> Rob> ~ entirely of word characters) to its left to be interpreted as a string 
> (as of
> Rob> ~ 5.001). This includes words that might otherwise be considered a 
> constant or
> Rob> ~ function call.
> 
> So we just need to add "but does not start with a digit" to that sentence.
> That's true in folklore, but not in the docs yet.  Yeah, docbug.
> I'm sure the author there intended the same definition as is used for
> Perl identifiers (variable names, package names, etc).

(That is some wide quoting!)

That isn't quite true, either.  The dash can be the first character, which is
not true of identifiers.

  DB<1> x [ -x => 1 ]
  0  ARRAY(0x18010cc)
 0  '-x'
 1  1

-- 
rjbs

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




Re: Time format

2006-11-15 Thread Ricardo SIGNES
* Jm lists <[EMAIL PROTECTED]> [2006-11-15T09:57:44]
> Hi members,
> 
> I want to get this format of time:
> 
> 11.07.06 12:00 pm
> 
> can you tell me how to get it?(maybe need to be translated from the
> 'localtime') Thanks.

Consult "perldoc -f localtime":

  #012 3 45 6 7 8
  my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;

  $string = sprintf '%02u.%02u.%02u %02u:%02u %s',
$mon + 1,
$mday,
substr($year, -2, 2),
$hour % 12,
$min,
($hour > 12 ? 'pm' : 'am');

  print "$string\n";

Is all of that clear?

-- 
rjbs

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




Re: better way to skip first few lines of file read?

2006-12-27 Thread Ricardo SIGNES
* "Dr.Ruud" <[EMAIL PROTECTED]> [2006-12-27T13:27:49]
>   <$TRACECSV> while $. <= 4;

$. is not well-known to many Perl programmers.

  <$TRACECSV> for 1 .. 4;

-- 
rjbs

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