|
List Info
Thread: Perl Noob
|
|
| Perl Noob |

|
2007-09-18 12:17:19 |
|
Hey all, I joined the group to get some Perl knowledge, but I don't see much going back 'n forth. Is this group for advance perl users? Or can I get more info.
Thanks,
em
|
| Re: Perl Noob |

|
2007-09-18 12:30:39 |
|
Emmanuel,
It's been years since I've gone to a meeting, but I believe this group is open to perl users of any level. People mostly post when they have a question for a project they are working on. The best way to learn (for me) is to just do it. If you start working on something and get stuck, feel free to post a question.
Others can probably point you to some good websites for learning. Seeing that you use Gmail, you probably see some helpful links off to the right while viewing this email right now, as I do.
A good beginner book is "Learning Perl". It is one of the few programming books I've actually read page by page.
I hope that helps...
John
On 9/18/07, Emmanuel Mejias < emmanuel.mejias gmail.com">emmanuel.mejias gmail.com> wrote:
Hey all, I joined the group to get some Perl knowledge, but I don't see much going back 'n forth. Is this group for advance perl users? Or can I get more info.
Thanks,
em
_______________________________________________ kc mailing list pm.org">kc pm.org
http://mail.pm.org/mailman/listinfo/kc
|
| Re: Perl Noob |

|
2007-09-18 12:45:31 |
On Tue, Sep 18, 2007 at 12:17:19PM -0500, Emmanuel Mejias
wrote:
> Hey all, I joined the group to get some Perl knowledge,
but I don't see much
> going back 'n forth. Is this group for advance perl
users? Or can I get more
> info.
Welcome, Emmanual!
The group is open to everyone interested in perl. It's a
pretty
low-traffic list, and the group doesn't have very large
meetings when
we do get together. I do think, though, that there's pretty
useful
information here when a specific question comes up. So,
please feel
free to ask whatever you like.
Some other good places to go might be:
http://www.perl.org/doc
s.html for some "intro" stuff
http://perldoc.perl.org/
for documentation on core modules
http://perl101.org/ a
newish introductory documentation site
http://search.cpan.org/
to find out about additional modules
http://use.perl.org/ a
popular perl community
http://www.perlmonks.org/
a> a bit more advanced perl community
http://perlbuzz.com/ a
newish perl news site
Welcome, and I hope you enjoy using perl!
-Andy
_______________________________________________
kc mailing list
kc pm.org
http://mail.pm
.org/mailman/listinfo/kc
|
|
| Re: Perl Noob |
  United States |
2007-09-18 12:38:33 |
On Tue, 18 Sep 2007 12:30:39 -0500
"John Reinke" <jmreinke gmail.com> wrote:
> Others can probably point you to some good websites for
learning.
> Seeing that you use Gmail, you probably see some
helpful links off to
> the right while viewing this email right now, as I do.
Here are some sites that you'll want to use as resources:
www.cpan.org and search.cpan.org
www.perlmonks.org
use.perl.org
planet.perl.org
perlmonks is a great place to get a quick question
answered
and CPAN is the place you go to find modules for specific
tasks so you don't have to re-invent the wheel yourself.
-------------------------------------------------------
Frank Wiles, Revolution Systems, LLC.
Personal : frank wiles.org http://www.wiles.org
Work : frank revsys.com http://www.revsys.com
_______________________________________________
kc mailing list
kc pm.org
http://mail.pm
.org/mailman/listinfo/kc
|
|
| Re: Perl Noob |
  United States |
2007-09-18 14:01:47 |
On Tue, 18 Sep 2007 13:48:02 -0500
"Emmanuel Mejias" <emmanuel.mejias gmail.com> wrote:
> Cool! Thanks all for the feeback and links. I've hit a
few of those
> in the past as well. I'm like John as well, I need to
do it to learn
> it. I've been in the BASH world so a lot of this stuff
is new to me
> and I'm trying to relate how some of the things you can
do in Bash
> how they work in Perl.
>
> Well here goes. I just recently started taking an
online course in
> Perl and I've also been using Perl by Example book as a
reference. In
> one of my exercises I have to write a script that
prints out a sorted
> list of environment variables. Well for some reason it
is only
> printing out 3 of the 5 that I specified. It doesn't
matter what
> order I put the environment variables in, it just
prints out every
> other one. In this case it prints out HOME, HOSTNAME
and USER, but
> leaves out TERM and SHELL. What am I not doing right in
my code?
>
> #!/usr/bin/perl
>
> %env = ('USER',
> 'SHELL',
> 'HOSTNAME',
> 'TERM',
> 'HOME');
>
> foreach $key (sort(keys(%env))){
> print "$env $ENV{$key}n";
> }
> Thoughts?
You're using a hash like an array when you shouldn't be:
What that is doing is creating this:
$env = 'SHELL';
$env = 'TERM';
$env = '';
Do this instead:
my envs = qw( USER SHELL HOSTNAME TERM HOME );
foreach my $env ( envs ) {
print "$env $ENV{$env}n";
}
-------------------------------------------------------
Frank Wiles, Revolution Systems, LLC.
Personal : frank wiles.org http://www.wiles.org
Work : frank revsys.com http://www.revsys.com
_______________________________________________
kc mailing list
kc pm.org
http://mail.pm
.org/mailman/listinfo/kc
|
|
| Re: Perl Noob |

|
2007-09-18 15:21:16 |
|
Okay I'll give that a try. I think that he wanted us to use the hash that was in the lesson. thanks again!
On 9/18/07, Frank Wiles < frank wiles.org">frank wiles.org> wrote:
On Tue, 18 Sep 2007 13:48:02 -0500 "Emmanuel Mejias" < emmanuel.mejias gmail.com">
emmanuel.mejias gmail.com> wrote:
> Cool! Thanks all for the feeback and links. I've hit a few of those > in the past as well. I'm like John as well, I need to do it to learn > it. I've been in the BASH world so a lot of this stuff is new to me
> and I'm trying to relate how some of the things you can do in Bash > how they work in Perl. > > Well here goes. I just recently started taking an online course in > Perl and I've also been using Perl by Example book as a reference. In
> one of my exercises I have to write a script that prints out a sorted > list of environment variables. Well for some reason it is only > printing out 3 of the 5 that I specified. It doesn't matter what
> order I put the environment variables in, it just prints out every > other one. In this case it prints out HOME, HOSTNAME and USER, but > leaves out TERM and SHELL. What am I not doing right in my code?
> > #!/usr/bin/perl > > %env = ('USER', > 'SHELL', > 'HOSTNAME', > 'TERM', > 'HOME'); > > foreach $key (sort(keys(%env))){
> print "$env $ENV{$key}n"; > } > Thoughts?
You're using a hash like an array when you shouldn9;t be:
What that is doing is creating this:
$env = 'SHELL';
$env{HOSTNAME} = 'TERM'; $env{HOME} = '';
Do this instead:
my envs = qw( USER SHELL HOSTNAME TERM HOME );
foreach my $env ( envs ) { print "$env $ENV{$env}n";
}
------------------------------------------------------- Frank Wiles, Revolution Systems, LLC. Personal : frank wiles.org">frank wiles.org http://www.wiles.org
Work : frank revsys.com">frank revsys.com http://www.revsys.com
|
| Re: Perl Noob |

|
2007-09-18 18:35:01 |
|
Well, that didn't work. It just gave me a print out of USER TERM HOSTNAME and SHELL instead of actual 'username', 'xterm', some host, and /bin/bash.
right now the way i have it it just gives me...
xterm emejias1
....instead of...
/home/emejias1 /bin/bash xterm emejias1
On 9/18/07, Emmanuel Mejias < emmanuel.mejias gmail.com">
emmanuel.mejias gmail.com> wrote:Okay I'll give that a try. I think that he wanted us to use the hash that was in the lesson. thanks again!
On 9/18/07, Frank Wiles < frank wiles.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">frank wiles.org
> wrote:
On Tue, 18 Sep 2007 13:48:02 -0500
"Emmanuel Mejias" < emmanuel.mejias gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
emmanuel.mejias gmail.com> wrote:
> Cool! Thanks all for the feeback and links. I've hit a few of those > in the past as well. I'm like John as well, I need to do it to learn > it. I've been in the BASH world so a lot of this stuff is new to me
> and I'm trying to relate how some of the things you can do in Bash > how they work in Perl. > > Well here goes. I just recently started taking an online course in > Perl and I've also been using Perl by Example book as a reference. In
> one of my exercises I have to write a script that prints out a sorted > list of environment variables. Well for some reason it is only > printing out 3 of the 5 that I specified. It doesn't matter what
> order I put the environment variables in, it just prints out every > other one. In this case it prints out HOME, HOSTNAME and USER, but > leaves out TERM and SHELL. What am I not doing right in my code?
> > #!/usr/bin/perl > > %env = ('USER', > 'SHELL', > 'HOSTNAME', > 'TERM', > 'HOME'); > > foreach $key (sort(keys(%env))){
> print "$env $ENV{$key}n"; > } > Thoughts?
You're using a hash like an array when you shouldn9;t be:
What that is doing is creating this:
$env = 'SHELL';
$env{HOSTNAME} = 'TERM'; $env{HOME} = '';
Do this instead:
my envs = qw( USER SHELL HOSTNAME TERM HOME );
foreach my $env ( envs ) { print "$env $ENV{$env}n";
}
------------------------------------------------------- Frank Wiles, Revolution Systems, LLC. Personal : frank wiles.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
frank wiles.org http://www.wiles.org
Work : frank revsys.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">frank revsys.com
http://www.revsys.com
|
| Re: Perl Noob |
  United States |
2007-09-18 19:05:51 |
# from Emmanuel Mejias
# on Tuesday 18 September 2007 16:35:
>> > > %env = ('USER',
>> > > 'SHELL',
>> > > 'HOSTNAME',
>> > > 'TERM',
>> > > 'HOME');
>> > >
>> > > foreach $key (sort(keys(%env))){
>> > > print "$env $ENV{$key}n";
>> > > }
Your code has an undeclared variable, which would throw an
error had you
used strictures and warnings.
>Well, that didn't work. It just gave me a print out of
USER TERM
>HOSTNAME and SHELL instead of actual 'username',
'xterm', some host,
>and /bin/bash.
Not sure about that. Hard to tell without seeing the code.
>right now the way i have it it just gives me...
>xterm
>emejias1
It should just be refusing to compile, but you did not use
strict.
Your %env as-written is a hash (and has an odd number of
elements, which
would also trigger a warning had you used warnings.) Thus,
keys(%env)
is only qw(USER HOSTNAME HOME) because 'SHELL' and 'TERM'
are values.
You wanted to declare it as 'my env = (...', which would be
an array.
The sigils can be a bit confusing at first, but once you
understand
them, they're quite readable.
>>>> I just recently started taking an online
course in
>>>> Perl and I've also been using Perl by
Example book as a reference.
Please tell me that book mentions strictures very early. If
not, throw
it away and read `perldoc perlintro` and the definitive
"Programming
Perl" (possibly "Learning Perl", but really
the camel is the way to
go.)
It would also be nice if you did not top-post to the mailing
list.
#!/usr/bin/perl
use warnings;
use strict;
my env_keys = qw(USER SHELL HOSTNAME TERM HOME);
foreach my $key ( env_keys) {
print "$key: $ENV{$key}n";
}
You will then notice that some of those are undefined and
thus warn
about the concatenation. To deal with that, you'll want to
check
exists($ENV{$key}) or defined($ENV{$key}) -- they are subtly
different.
Above all, please use strict and use warnings and declare
your variables
with 'my'. Learning perl without those three things is
altogether
unpredictable and pretty unpleasant for everyone on the list
as well.
If you're writing one-liners, you can also have these safety
nets with
the -M switch:
$ perl -Mwarnings -Mstrict -e '%foo = qw( bar baz bort)'
Global symbol "%foo" requires explicit package
name at -e line 1.
Execution of -e aborted due to compilation errors.
$ perl -Mwarnings -Mstrict -e 'my %foo = qw( bar baz
bort)'
Odd number of elements in hash assignment at -e line 1.
Once you have good coding habits that run clean under strict
and
warnings, you can then spend your debugging time on the
actual
algorithmic mistakes rather than typos.
--Eric
--
software: a hypothetical exercise which happens to
compile.
---------------------------------------------------
http://scratchcomputing.c
om
---------------------------------------------------
_______________________________________________
kc mailing list
kc pm.org
http://mail.pm
.org/mailman/listinfo/kc
|
|
| Re: Perl Noob |

|
2007-09-19 02:22:17 |
On 9/18/07, Eric Wilhelm <scratchcomputing gmail.com> wrote:
> # from Emmanuel Mejias
> # on Tuesday 18 September 2007 16:35:
>
> Please tell me that book mentions strictures very
early. If not, throw
> it away and read `perldoc perlintro` and the definitive
"Programming
> Perl" (possibly "Learning Perl", but
really the camel is the way to
> go.)
Learning Perl goes over Pragmas (strict,warnings).
on page 63 (Chapter 4 Subroutines) talks about using 'use
strict;'
when writing code.
warnings are pretty early on seems to start on page 24 with
'perl -w script.pl'
> It would also be nice if you did not top-post to the
mailing list.
Uh oh, hopefully this doesn't become a problem like KCLUG
mailing list. /me runs
> You will then notice that some of those are undefined
and thus warn
> about the concatenation. To deal with that, you'll
want to check
> exists($ENV{$key}) or defined($ENV{$key}) -- they are
subtly different.
>
> Above all, please use strict and use warnings and
declare your variables
> with 'my'. Learning perl without those three things is
altogether
> unpredictable and pretty unpleasant for everyone on the
list as well.
I totally agree about using pragmas (strict, warnings) for
all programs.
_______________________________________________
kc mailing list
kc pm.org
http://mail.pm
.org/mailman/listinfo/kc
|
|
| Re: Perl Noob |
  United States |
2007-09-19 02:36:16 |
# from djgoku
# on Wednesday 19 September 2007 00:22:
>warnings are pretty early on seems to start on page 24
with 'perl -w
> script.pl'
As of (roughly) v5.6.2, -w is different though. See perlrun
and then
perllexwarn. With '-w', you're enabling warnings globally
-- on all of
the modules being loaded. This is sometimes nice to check,
but (e.g.
in tests) not if the modules weren't tested with warnings
enabled.
--Eric
--
We who cut mere stones must always be envisioning
cathedrals.
--Quarry worker's creed
---------------------------------------------------
http://scratchcomputing.c
om
---------------------------------------------------
_______________________________________________
kc mailing list
kc pm.org
http://mail.pm
.org/mailman/listinfo/kc
|
|
|
|