Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lots of questions about perl

Status
Not open for further replies.

tchatzi

Technical User
Dec 15, 2004
744
GR
Hello to everyone,

I 'm new in perl programming, i downloaded lots of tutorials, and i also bought a book. So i started two days ago studing perl. I think i will have have lots of question till i get to know perl that good, and some of them, might sound stupid but there is no other way to answer my questions exept asking you guys. Thanks in advance for your help and your time.
I read in the book that there is a CGI something way to program with perl, what is this CGI?
and as i go on the pages writing the code this guy explains
i got these two lines
$name = ~ s/\W.*//;
$name = ~ tr/A-Z/a-z/;
he says that they are for cutting unwanted characters from the main name that you type, and also for turning all the capitals to small characters.
but the problem is this:

Use of uninitialized value in substitution (s///) at C:\Documents and Settings\P
engo\My Documents\Perl Code\Text-1.pl line 26, <STDIN> line 2.
Use of uninitialized value in transliteration (tr///) at C:\Documents and Settin
gs\Pengo\My Documents\Perl Code\Text-1.pl line 27, <STDIN> line 2.

and the program goes on without changing any capital characters.
are the two commands spelling different, is it a syntax error?
 
Loads of defintions of CGI can be found on google, take a look at this link:
I haven't yet been able to find an answer to the uninitialized value problem, although it would appear that it is merely a warning rather than an error, maybe include some more of your code so that we can see if it's a syntax error.

Also, look into using the lc() function for changing the capital letters, i.e.
Code:
$name = lc $name;

Or likewise, uc EXPR for making it uppercase, or ucfirst EXPR for upper casing the first letter of a string.

This web site is an excellent resource for learning perl:

Rob Waite
 
It seems that your $name variable doesn't have any value to perform operations on so perl is just alerting you to that fact.
 
For the 'uninitialized' problem, be sure there is no space between the '=' and the '~' characters.

With any embedded space between = and ~ your substitution and transliteration will not work on $name but on the default $_ variable that could be undefined.

--------------------

Denis
 
thank you all,
thanks for the site about CGI, and the site about learning perl,
the problem was the space between the '=' and the '~' characters. "unbelievable", this guy on the book says that spaces dont make any difference.
but how can i know when the default $_ variable is being used, and how can i know when to use it on purpose?
Also i was wondering why this guy uses this 'tr' which looks complicate, and not 'lc' which is so simple?
 
The spaces don't make a difference between operators and operands, so
Code:
$a=3+2;
$a = 3 + 2;
$a          =
3

+

2;
are all treated the same by the interpreter. But =~ is a single operator that happens to be two characters long. You wouldn't expect $perluserpengo to be accepted if you wrote it as $perl user pengo, and this is the same.

So don't be too hard on the author. Which book is it, anyway? Hope it's not the camel book. You won't get away with dissing Larry or Randall on this forum...[smile]
 
It is called 'learn perl' it has a camel for a cover, it is Greek and it has 330 pages, although it says that it is written by Schwarrtz and Christiansen but during the translation maybe the translator run out of pages so he might missed somethings. But i also have the 'Programming Perl' the camel book by Larry, Christiansen and Orwant which is a 1000 pages book, but it is written in english so i prefferd to start with the fammiliar language book and then going on with the rest.
 
I think the reason to use tr instead of lc in the book is the author is trying to show you examples of regular expression which PERL is really good at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top