Re: Brackets in scalar and array

2014-05-29 Thread Shawn H Corey
On Thu, 29 May 2014 16:02:44 -0700
Jim Gibson  wrote:

> 
> On May 29, 2014, at 3:34 PM, Sherman Willden wrote:
> 
> > Maybe I'm missing the point but isn't the following code the
> > problem's answer? Please let me know if I am off base.
> 
> Just a bit off (see below).
> 
> > #!/usr/bin/perl
> > 
> > my @test = "a b c";
> 
> That is a scalar on the right-hand side. You end up with a
> one-element array in which the first and only element is the string
> 'a b c'. Shawn and I were using the qw() operator, which splits a
> string on whitespace and returns a list:
> 
>   my @test = qw(a b c);
> 
> which is equivalent to and shorter than:
> 
>   my @test = ( 'a', 'b', 'c');
> 
> 
> 

See http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Brackets in scalar and array

2014-05-29 Thread Jim Gibson

On May 29, 2014, at 3:34 PM, Sherman Willden wrote:

> Maybe I'm missing the point but isn't the following code the problem's 
> answer? Please let me know if I am off base.

Just a bit off (see below).

> #!/usr/bin/perl
> 
> my @test = "a b c";

That is a scalar on the right-hand side. You end up with a one-element array in 
which the first and only element is the string 'a b c'. Shawn and I were using 
the qw() operator, which splits a string on whitespace and returns a list:

  my @test = qw(a b c);

which is equivalent to and shorter than:

  my @test = ( 'a', 'b', 'c');



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Brackets in scalar and array

2014-05-29 Thread Sherman Willden
Maybe I'm missing the point but isn't the following code the problem's
answer? Please let me know if I am off base.

Thank you;

Sherman

#!/usr/bin/perl

my @test = "a b c";

($test)=(@test);
print "\$test: $test\n";

@test = "a b c";

$test = @test;
print "\$test: $test\n";


# output lines after running this file
# $test: a b c
# $test: 1


On Thu, May 29, 2014 at 2:45 PM, Shawn H Corey 
wrote:

> On Thu, 29 May 2014 13:36:11 -0700
> Jim Gibson  wrote:
>
> > Try it yourself:
> >
> > % perl -e '@t=qw(1 2 3);$t=@t;print qq($t\n);'
> > 3
> > % perl -e '@t=qw(1 2 3);($t)=@t;print qq($t\n);'
> > 1
> > % perl -e '@t=qw(1 2 3);($t)=(@t);print qq($t\n);'
> > 1
>
> This would be clearer if you used letters:
>
> $ perl -E'@t=qw( a b c );$t=@t;say$t'
> 3
> $ perl -E'@t=qw( a b c );($t)=@t;say$t'
> a
> $ perl -E'@t=qw( a b c );($t)=(@t);say$t'
> a
>
>
> --
> Don't stop where the ink does.
> Shawn
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Brackets in scalar and array

2014-05-29 Thread Shawn H Corey
On Thu, 29 May 2014 16:27:36 -0500
Steve Kaftanski  wrote:

> Hope this helps! -Steve Kaftanski, MadMongers.org (Madison.pm
> Wisconsin).

Here are some links you might find useful:

*   official site 

*   beginners' help 

*   advance help 

*   documentation 

*   news 

*   repository 

*   blog 

*   regional groups 



-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Brackets in scalar and array

2014-05-29 Thread Steve Kaftanski
I am also a long-time lurker / First time responder, so hopefully I'll
answer acceptably per the email-list conventions...
  I will assume that some of the basic references are available to you (or
that others will cite them correctly... as they appear to be doing; many
responses so far.)
  Anyway, *syntax* is relatively easy to answer; *why* someone might have
written such a thing, not always as much...

I would personally interpret this question in the way I would normally see
it: "Why is someone putting parentheses around these variables?"

When confronted with questions like this (and I often encounter obscure
Perl in my daily work, so that's fairly common here) I start by directing
the questioner to two things:
  google site:perlmonks.org parentheses variable
  google site:stackoverflow.com parentheses variable

My justification for this is, when trying to figure out why one piece of
code is a certain way, it helps to go to the sites where people who write
code share what they're doing, and other people comment knowledgeably about
it.

(I'm sure there are other sites that others recommend; these are just the
two I've found most useful.)

Scanning through the results, I might use them to answer someone who asked
the question the way I wrote it... more-or-less this way:
  Left-hand-side: Putting parentheses around a scalar (or a set of scalars)
is a way to assign values to everything in the list all at the same
time (even if it's just have one thing getting one assignment).
  Right-hand-side: Putting parentheses around an array is shorthand for
getting the first element of the array (by converting the elements into a
list -- changing from scalar to list context)
 ...in the same way that leaving the parentheses off and not specifying
a single element, will return the number of elements in the array.

Further, it's worth noting that putting parentheses around a single scalar
on the left-hand-side of an assignment (a list of one thing)... is subtle.
 For example, in

http://stackoverflow.com/questions/10031455/perl-using-my-with-parentheses-and-only-one-variable

   I see that http://stackoverflow.com/users/2766176/brian-d-foy  (who
answers these types of questions for a living) is essentially saying on one
hand that he does it just because he's used to typing "my (" and some
stuff, and then ");" and that just having one thing isn't a problem; but he
also notes farther down
http://perldoc.perl.org/perlfaq4.html#What-is-the-difference-between-a-list-and-an-array%3f
for completeness.

Hope this helps! -Steve Kaftanski, MadMongers.org (Madison.pm Wisconsin).



On Thu, May 29, 2014 at 3:20 PM, James Kerwin  wrote:

> Hello all, long time lurker, first time requester...
>
> I have a Perl exam tomorrow and came across a question that I just cannot
> find an answer to (past paper, this isn't cheating or homework etc.).
>
> Explain the difference between:
>
> ($test)=(@test);
>
> And
>
> $test=@test;
>
> If anybody could shed any light on this I'd be very grateful.
>
> Thanks,
> James.
>


Re: Brackets in scalar and array

2014-05-29 Thread Andy Bach
On Thu, May 29, 2014 at 3:20 PM, James Kerwin  wrote:

> Explain the difference between:
>
> ($test)=(@test);
>
> And
>
> $test=@test;
>

Parens on the left make it a "list" context, parens on the right make it a
list.
Bare scalar on the left make it "scalar context, bare array assigned in a
scalar context return a scalar - that is, the number of elements. So, in
the first, @test gets unrolled to a list of elements and assigned in list
context, the first element gets assigned to the first list element in the
LHS list, i.e. $test - as if
$test = $test[0];

Note, in this case, the parens are optional on the RHS, as the same thing
would happen in
($test) = @test;

you can add to that LHS list
my ($test1, $test2, $test3, @test4) = @test;

and elements 0, 1, 2 go into the scalars and the rest is "slurped" into
@test4. If there not enough elements, they get "undef".

An array in scalar context returns it's element count, so you can do:
if ( @test == 4 ) {
   print "There's 4 things in \@test!\n";
}

-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: Brackets in scalar and array

2014-05-29 Thread James Kerwin
It seems so obvious now. Should possibly have just tested it myself before
asking...

Thank you all for the explanations!
On 29 May 2014 21:36, "Jim Gibson"  wrote:

>
> On May 29, 2014, at 1:20 PM, James Kerwin wrote:
>
> > Hello all, long time lurker, first time requester...
> >
> > I have a Perl exam tomorrow and came across a question that I just
> cannot find an answer to (past paper, this isn't cheating or homework etc.).
> >
> > Explain the difference between:
> >
> > ($test)=(@test);
> >
> > And
> >
> > $test=@test;
> >
> > If anybody could shed any light on this I'd be very grateful.
>
> The difference is the "context" of the assignment: "scalar" or "list", and
> how @test (or (@test)) is evaluated in that context.
>
> In the first statement ($test) = (@test), the parentheses around $test in
> the left-hand side (LHS) of the assignment places the evaluation of the
> right-hand side (RHS) in list context. In list context, with two lists on
> either side of the assignment operator (=), assignment is made from each
> element on the RHS to the corresponding element on the LHS. Therefore, the
> one and only element on the LHS ($test) gets assigned the value of the
> first element of the RHS, and $test ends up with the value of $test[0].
>
> In the second statement, the assignment is done in scalar context, and the
> RHS is evaluated in scalar context. A list evaluated in scalar context
> returns the number of elements in the list, and $test is assigned the value
> ($#test+1).
>
> Note that the parentheses around @test in the first statement are
> irrelevant. The context is list with or without them.
>
> Try it yourself:
>
> % perl -e '@t=qw(1 2 3);$t=@t;print qq($t\n);'
> 3
> % perl -e '@t=qw(1 2 3);($t)=@t;print qq($t\n);'
> 1
> % perl -e '@t=qw(1 2 3);($t)=(@t);print qq($t\n);'
> 1
>
>
>
>


Re: Brackets in scalar and array

2014-05-29 Thread Shawn H Corey
On Thu, 29 May 2014 13:36:11 -0700
Jim Gibson  wrote:

> Try it yourself:
> 
> % perl -e '@t=qw(1 2 3);$t=@t;print qq($t\n);'
> 3
> % perl -e '@t=qw(1 2 3);($t)=@t;print qq($t\n);'
> 1
> % perl -e '@t=qw(1 2 3);($t)=(@t);print qq($t\n);'
> 1

This would be clearer if you used letters:

$ perl -E'@t=qw( a b c );$t=@t;say$t'
3
$ perl -E'@t=qw( a b c );($t)=@t;say$t'
a
$ perl -E'@t=qw( a b c );($t)=(@t);say$t'
a


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Brackets in scalar and array

2014-05-29 Thread Jim Gibson

On May 29, 2014, at 1:20 PM, James Kerwin wrote:

> Hello all, long time lurker, first time requester...
> 
> I have a Perl exam tomorrow and came across a question that I just cannot 
> find an answer to (past paper, this isn't cheating or homework etc.).
> 
> Explain the difference between:
> 
> ($test)=(@test);
> 
> And
> 
> $test=@test;
> 
> If anybody could shed any light on this I'd be very grateful.

The difference is the "context" of the assignment: "scalar" or "list", and how 
@test (or (@test)) is evaluated in that context.

In the first statement ($test) = (@test), the parentheses around $test in the 
left-hand side (LHS) of the assignment places the evaluation of the right-hand 
side (RHS) in list context. In list context, with two lists on either side of 
the assignment operator (=), assignment is made from each element on the RHS to 
the corresponding element on the LHS. Therefore, the one and only element on 
the LHS ($test) gets assigned the value of the first element of the RHS, and 
$test ends up with the value of $test[0].

In the second statement, the assignment is done in scalar context, and the RHS 
is evaluated in scalar context. A list evaluated in scalar context returns the 
number of elements in the list, and $test is assigned the value ($#test+1).

Note that the parentheses around @test in the first statement are irrelevant. 
The context is list with or without them.

Try it yourself:

% perl -e '@t=qw(1 2 3);$t=@t;print qq($t\n);'
3
% perl -e '@t=qw(1 2 3);($t)=@t;print qq($t\n);'
1
% perl -e '@t=qw(1 2 3);($t)=(@t);print qq($t\n);'
1
 



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Brackets in scalar and array

2014-05-29 Thread Hao Wu
Hi,
you can find the answer here,

http://perlmaven.com/scalar-and-list-context-in-perl

Good Luck to your exam!


On Thu, May 29, 2014 at 1:20 PM, James Kerwin  wrote:

> Hello all, long time lurker, first time requester...
>
> I have a Perl exam tomorrow and came across a question that I just cannot
> find an answer to (past paper, this isn't cheating or homework etc.).
>
> Explain the difference between:
>
> ($test)=(@test);
>
> And
>
> $test=@test;
>
> If anybody could shed any light on this I'd be very grateful.
>
> Thanks,
> James.
>


Brackets in scalar and array

2014-05-29 Thread James Kerwin
Hello all, long time lurker, first time requester...

I have a Perl exam tomorrow and came across a question that I just cannot
find an answer to (past paper, this isn't cheating or homework etc.).

Explain the difference between:

($test)=(@test);

And

$test=@test;

If anybody could shed any light on this I'd be very grateful.

Thanks,
James.


Re: How to change username in Pause account

2014-05-29 Thread David Precious
On Thu, 29 May 2014 10:59:56 +
Priyal Jain  wrote:

> Hello,
> 
> I want to change my username in PAUSE, how should I do that.

I don't think you can change your PAUSE username.  After all, it would
require all mirrors to know to rename your PAUSE dir, invalidate old
links, etc.

You can, however, change the display name used for it, at:

https://pause.perl.org/pause/authenquery?ACTION=edit_cred



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




How to change username in Pause account

2014-05-29 Thread Priyal Jain
Hello,

I want to change my username in PAUSE, how should I do that.


Thanks
Regards
Priyal



RE: Error in installing "Bundle::Expect" as dependency for some other module using CPAN

2014-05-29 Thread Priyal Jain
Hello,

I am still getting error, Following is the error message:

root@priyal:/usr/local/share/perl/5.14.2# cpanm Net::Netconf
--> Working on Net::Netconf
Fetching 
http://search.cpan.org/CPAN/authors/id/J/JP/JPRIYAL/Net-Netconf-0.01.zip ... OK
! Bad archive: [testing: Net-Netconf-0.01/CHANGES   OK] Net-Netconf-0.01.zip
! Failed to unpack Net-Netconf-0.01.zip: no directory
! Failed to fetch distribution Net-Netconf-0.01

Kindly help

Thanks
Regards
Priyal

From: Sebastien Feugere [mailto:seb.feug...@gmail.com]
Sent: Thursday, May 29, 2014 11:56 AM
To: Priyal Jain
Cc: beginners@perl.org
Subject: Re: Error in installing "Bundle::Expect" as dependency for some other 
module using CPAN

Successfully installed it using "cpanm Net::Netconf". You should take a look at 
cpanminus, it will make your working life easier.
https://metacpan.org/pod/App::cpanminus

Note that it fails if you omit the capital "N" in "Netconf".
If it don't work for you, you could maybe post the full failure log ?



~$&bast1

On Thu, May 29, 2014 at 12:32 PM, Priyal Jain 
mailto:jpri...@juniper.net>> wrote:
Hello,

I have uploaded my Perl module in CPAN, 
http://search.cpan.org/search?mode=all&query=net%3A%3Anetconf, but when I am 
trying to install it using 'cpan Net::netconf' its saying don't know what it is 
/Net::Netconf/ , cannot install it.

Please suggest something, what is the issue.


Regards,
Thanks,
Priyal

_
From: Priyal Jain
Sent: Friday, May 16, 2014 2:11 PM
To: 'beginners@perl.org'
Subject: Error in installing "Bundle::Expect" as dependency for some other 
module using CPAN


Hello,

I am uploading my module Net::Netconf 
http://search.cpan.org/search?mode=all&query=net%3A%3Anetconf in CPAN, but its 
giving error of dependency not found for Bundle::Expect. I am mentioning all my 
dependency in Makefile.Pl
"use ExtUtils::MakeMaker;
our $VERSION ='0.01';
use 5.006;
WriteMakefile(
NAME => 'Net-Netconf',
AUTHOR   => 'Juniper Networks, Inc',
VERSION_FROM => 'Makefile.PL',
PREREQ_PM => {'XML::LibXML'=> '0', 'File::Which'=> '0', 
'Bundle::Expect'=>'0',},
ABSTRACT => 'netconf libraries for perl',

);"

But its giving error. Kindly help me.


Thnanks,
Priyal