[32090] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3354 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 17 14:09:26 2011

Date: Sun, 17 Apr 2011 11:09:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 17 Apr 2011     Volume: 11 Number: 3354

Today's topics:
    Re: grabbing a facebook group <Uno@example.invalid>
    Re: grabbing a facebook group <Uno@example.invalid>
    Re: grabbing a facebook group <tadmc@seesig.invalid>
    Re: grabbing a facebook group <tadmc@seesig.invalid>
        Help! How to pass array indexes to subroutine? <Joey@still_Learning.invalid>
    Re: Help! How to pass array indexes to subroutine? <fred.NO@SPAM.resel.fr>
    Re: Help! How to pass array indexes to subroutine? <tadmc@seesig.invalid>
    Re: Help! How to pass array indexes to subroutine? <Joey@still_Learning.invalid>
    Re: Help! How to pass array indexes to subroutine? <uri@StemSystems.com>
    Re: Help! How to pass array indexes to subroutine? <fred.NO@SPAM.resel.fr>
    Re: Help! How to pass array indexes to subroutine? <tadmc@seesig.invalid>
    Re: Help! How to pass array indexes to subroutine? <uri@StemSystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 16 Apr 2011 18:28:25 -0600
From: Uno <Uno@example.invalid>
Subject: Re: grabbing a facebook group
Message-Id: <90uqhaF3v7U1@mid.individual.net>

On 04/16/2011 11:26 AM, Sherm Pendley wrote:
> Uno<Uno@example.invalid>  writes:
>
>> Why is my terminal always telling me that 'YAML' is not installed,
>> while python-yaml is?
>
> Because YAML is a Perl module, and python-yaml is not.
>
> sherm--
>
$ man YAML
$ ysh
No command 'ysh' found, but there are 25 similar ones
ysh: command not found
$ perl fb1.pl
Global symbol "$app_id" requires explicit package name at fb1.pl line 8.
Global symbol "$api_key" requires explicit package name at fb1.pl line 9.
Global symbol "$secret" requires explicit package name at fb1.pl line 10.
BEGIN not safe after errors--compilation aborted at fb1.pl line 13.
$ man Moose
$ cat fb1.pl
#!/usr/bin/perl
use strict;
use warnings;

use Facebook;

   my $fb = Facebook->new(
     app_id => $app_id,
     api_key => $api_key,
     secret => $secret,
   );

   use Facebook::Signed;

   my $logged_in_fb = Facebook->new(
     signed => Facebook::Signed->new(
       secret => $secret,
       facebook_data => $facebook_cookie_for_your_application_as_text,
     ),
     app_id => $app_id,
     secret => $secret,
         api_key => $api_key,
   );

   # If you dont provide secret, it will try to fetch it from signed values
   my $shorter_logged_in_fb = Facebook->new(
     signed => Facebook::Signed->new(
       secret => $secret,
       facebook_data => $facebook_cookie_for_your_application_as_text,
     ),
     app_id => $app_id,
     api_key => $api_key,
   );

   # You need to have Facebook::Graph installed so that this works
   my $gettys_facebook_profile = $fb->graph->query
     ->find(100001153174797)
     ->include_metadata
     ->request
     ->as_hashref;

__END__

$

I had hoped that getting YAML, Moose, Facebook::Signed and so forth was 
going to help me resolve these 3 errors, but not so.  Ideas?
-- 
Uno


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

Date: Sat, 16 Apr 2011 18:31:48 -0600
From: Uno <Uno@example.invalid>
Subject: Re: grabbing a facebook group
Message-Id: <90uqnlF53iU1@mid.individual.net>

On 04/16/2011 08:26 AM, Mart van de Wege wrote:
> Uno<Uno@example.invalid>  writes:
>
>> On 04/16/2011 02:39 AM, Mart van de Wege wrote:
>>
>>> Because your system is trying to run a shell script instead of perl.
>>>
>>> When you launch an executable text file, Linux will look at the first
>>> two characters: if these are #!, then the rest of the line will be used
>>> as the interpreter command to run the text file with. If the first two
>>> characters are *not* #!, then the code will be run by your shell.
>>>
>>> Now take a *good* look at your code. What are the first two characters?
>>>
>>> Mart
>>>
>>
>> $ perl fb1.pl
>> Global symbol "$app_id" requires explicit package name at fb1.pl line 8.
>> Global symbol "$api_key" requires explicit package name at fb1.pl line 9.
>> Global symbol "$secret" requires explicit package name at fb1.pl line 10.
>> BEGIN not safe after errors--compilation aborted at fb1.pl line 13.
>> $
>>
>> It was a single, white space.  I find that white space is not your
>> friend in perl.
>
> When people do you the courtesy of patiently explaining how something
> works, please do have the courtesy in return of actually *reading* what
> they wrote.
>
> Mart
>

Whatever, Mart, I think you overestimate your courtesy when you try to 
tell me what I read.  The first 2 characters were whitespace and then a 
hash.  Now I've got my shebang line correct and am moving on ....
-- 
Uno


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

Date: Sat, 16 Apr 2011 23:08:23 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: grabbing a facebook group
Message-Id: <slrniqkpkq.98r.tadmc@tadbox.sbcglobal.net>

Uno <Uno@example.invalid> wrote:

>>> I find that white space is not your
                ^^^^^^^^^^^
>>> friend in perl.
           ^^^^^^^
>>
>> When people do you the courtesy of patiently explaining how something
>> works, please do have the courtesy in return of actually *reading* what
>> they wrote.


> Whatever, Mart, 


That's enough for me.

So long.


> I think you overestimate your courtesy when you try to 
> tell me what I read.  


You read it, but did not understand it!


> The first 2 characters were whitespace


 ... so there was no perl.

So there was no "white space in perl" anywhere in the thread.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Sat, 16 Apr 2011 23:12:17 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: grabbing a facebook group
Message-Id: <slrniqkps4.98r.tadmc@tadbox.sbcglobal.net>

Uno <Uno@example.invalid> wrote:

> Global symbol "$app_id" requires explicit package name at fb1.pl line 8.

> #!/usr/bin/perl
> use strict;
> use warnings;
>
> use Facebook;
>
>    my $fb = Facebook->new(
>      app_id => $app_id,

> I had hoped that getting YAML, Moose, Facebook::Signed and so forth was 
> going to help me resolve these 3 errors, but not so.  


What made you think that those were germane to that error message?


> Ideas?


Ask perl for ideas:

    perl -Mstrict -Mdiagnostics -e '$app_id'

Global symbol "$app_id" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors (#1)
    (F) You've said "use strict" or "use strict vars", which indicates 
    that all variables must either be lexically scoped (using "my" or "state"), 
    declared beforehand using "our", or explicitly qualified to say 
    which package the global variable is in (using "::").


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Sat, 16 Apr 2011 12:05:47 -0700
From: "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>
Subject: Help! How to pass array indexes to subroutine?
Message-Id: <h4pjq6584g7tavn2on01odpbeuecqbb8fg@4ax.com>

I have an array:   @mod3Regions = ('','ridge1','ridge2','ridge3');

And a variable ,$valueOfInterest, that bitwise represents which selections
have been made. 

I can compute as follows:

for (my $j=1; $j<6; $j++) {
	$mask = 1 << $j-1;
	$zzz = $valueOfInterest & $mask;
	if ($zzz != 0) {
	print "$mod3Regions[$j], \n";
	}
	} 

I want to use a subroutine, but I can't get it to output the selected
array value. I'm doing this:

getValues($valueOfInterest, '$mod3Regions',4);

sub getValues($what, $who, 4) {
$_[0] = $what; $_[1] = $who; $_[2] = $counter;

for (my $j=1; $j<$count; $j++) {
$mask = 1 << $j-1;
$zzz = $what & $mask;
if ($zzz != 0) {

print "$who[$j], \n";

}
}

Which prints '$mod3Regions[1],'  '$mod3Regions[2],' etc.,instead of the
correct indexed array values for $who[$j]. What is wrong? How do I write
this properly?

Thanks in advance,
-- 
Joey


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

Date: Sun, 17 Apr 2011 00:00:44 +0200
From: =?utf-8?B?RnLDqWTDqXJpYw==?= Perrin <fred.NO@SPAM.resel.fr>
Subject: Re: Help! How to pass array indexes to subroutine?
Message-Id: <kggfwphluur.fsf@pc-df-301.priv.enst-bretagne.fr>

"Joey@still_Learning.invalid" <Joey@still_Learning.invalid> writes:
> I have an array:   @mod3Regions = ('','ridge1','ridge2','ridge3');
>
> And a variable ,$valueOfInterest, that bitwise represents which selections
> have been made. 
>
> I can compute as follows:
>
> for (my $j=1; $j<6; $j++) {
> 	$mask = 1 << $j-1;

Where does $mask comes from ? Add `use strict;' at the top of your
script (just after the shebang line).

> 	$zzz = $valueOfInterest & $mask;
> 	if ($zzz != 0) {
> 	print "$mod3Regions[$j], \n";
> 	}
> 	} 
>
> I want to use a subroutine, but I can't get it to output the selected
> array value. I'm doing this:
>
> getValues($valueOfInterest, '$mod3Regions',4);
>
> sub getValues($what, $who, 4) {

You just invented some syntax, there.

> $_[0] = $what; $_[1] = $who; $_[2] = $counter;

This is going to do the opposite of what you want.

sub getValues {
  my $what = shift;
  my $who  = shift;
  my $counter = shift || 4;

> for (my $j=1; $j<$count; $j++) {
> $mask = 1 << $j-1;
> $zzz = $what & $mask;

Use reprensentative variable names.

> if ($zzz != 0) {
>
> print "$who[$j], \n";

$who is a scalar. $who[$j] is the element of index $j inside @who. `use
strict' would have caught that error. Also, passing arrays to subs needs
some care; you have to pass a reference to the array to the sub.

> }
> }
>
> Which prints '$mod3Regions[1],'  '$mod3Regions[2],' etc.,instead of the
> correct indexed array values for $who[$j]. What is wrong? How do I write
> this properly?

Start with what I wrote above.

-- 
Frédéric Perrin -- http://tar-jx.bz


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

Date: Sat, 16 Apr 2011 19:29:28 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Help! How to pass array indexes to subroutine?
Message-Id: <slrniqkcqb.8v5.tadmc@tadbox.sbcglobal.net>

Joey@still_Learning.invalid <Joey@still_Learning.invalid> wrote:

> sub getValues($what, $who, 4) {


This is the Perl newsgroup.

Please post only actual Perl code here.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Sun, 17 Apr 2011 00:18:16 -0700
From: "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>
Subject: Re: Help! How to pass array indexes to subroutine?
Message-Id: <tk4lq61isrbdirvg8qa6m4e1f29qlmimv2@4ax.com>

Frédéric Perrin wrote:

>"Joey@still_Learning.invalid" <Joey@still_Learning.invalid> writes:
>> I have an array:   @mod3Regions = ('','ridge1','ridge2','ridge3');
>>
>> And a variable ,$valueOfInterest, that bitwise represents which selections
>> have been made. 
>>
>> I can compute as follows:
>>
>> for (my $j=1; $j<6; $j++) {
>> 	$mask = 1 << $j-1;
>
>Where does $mask comes from ? Add `use strict;' at the top of your
>script (just after the shebang line).
>
>> 	$zzz = $valueOfInterest & $mask;
>> 	if ($zzz != 0) {
>> 	print "$mod3Regions[$j], \n";
>> 	}
>> 	} 
>>
>> I want to use a subroutine, but I can't get it to output the selected
>> array value. I'm doing this:
>>
>> getValues($valueOfInterest, '$mod3Regions',4);
>>
>> sub getValues($what, $who, 4) {
>
>You just invented some syntax, there.

Actually, no. It's the same syntax as javascript (except for the $), and
Perl ignores the parameters. I write as much js as I write in Perl and
it's convenient to not have to change syntax rules if it's not essential.
>
>> $_[0] = $what; $_[1] = $who; $_[2] = $counter;
>
>This is going to do the opposite of what you want.
>
>sub getValues {
>  my $what = shift;
>  my $who  = shift;
>  my $counter = shift || 4;
>
>> for (my $j=1; $j<$count; $j++) {
>> $mask = 1 << $j-1;
>> $zzz = $what & $mask;
>
>Use reprensentative variable names.

Agree
>
>> if ($zzz != 0) {
>>
>> print "$who[$j], \n";
>
>$who is a scalar. $who[$j] is the element of index $j inside @who. `use
>strict' would have caught that error. Also, passing arrays to subs needs
>some care; you have to pass a reference to the array to the sub.
>
>> }
>> }
>>
>> Which prints '$mod3Regions[1],'  '$mod3Regions[2],' etc.,instead of the
>> correct indexed array values for $who[$j]. What is wrong? How do I write
>> this properly?
>
>Start with what I wrote above.

I did, and you led me to the solution. Thank you.

decodeRegions($ridges,6,@mod3Regions); //(buttons, counter, array)

sub decodeRegions {
	my ($what, $counter, @who) = @_;
	for (my $j=1; $j<$counter; $j++) {
	my $mask = 1 << $j-1;
	$buttonSelected = $what & $mask;
	if ($buttonSelected != 0) {
	print $who[$j].", \n";
	}
	}
}

Thanks again.
-- 
Joey


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

Date: Sun, 17 Apr 2011 04:34:52 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Help! How to pass array indexes to subroutine?
Message-Id: <8739lhmg2b.fsf@quad.sysarch.com>

>>>>> "JLi" == Joey@still Learning invalid <Joey@still_Learning.invalid> writes:

  JLi> Frédéric Perrin wrote:
  >> "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> writes:
  >>> I have an array:   @mod3Regions = ('','ridge1','ridge2','ridge3');
  >>> 
  >>> And a variable ,$valueOfInterest, that bitwise represents which selections
  >>> have been made. 
  >>> 
  >>> I can compute as follows:
  >>> 
  >>> for (my $j=1; $j<6; $j++) {
  >>> $mask = 1 << $j-1;
  >> 
  >> Where does $mask comes from ? Add `use strict;' at the top of your
  >> script (just after the shebang line).
  >> 
  >>> $zzz = $valueOfInterest & $mask;
  >>> if ($zzz != 0) {
  >>> print "$mod3Regions[$j], \n";
  >>> }
  >>> } 
  >>> 
  >>> I want to use a subroutine, but I can't get it to output the selected
  >>> array value. I'm doing this:
  >>> 
  >>> getValues($valueOfInterest, '$mod3Regions',4);
  >>> 
  >>> sub getValues($what, $who, 4) {
  >> 
  >> You just invented some syntax, there.

  JLi> Actually, no. It's the same syntax as javascript (except for the $), and
  JLi> Perl ignores the parameters. I write as much js as I write in Perl and
  JLi> it's convenient to not have to change syntax rules if it's not essential.

wow. perl uses that for prototypes, it isn't ignoring them. please don't
be coding like this on any production job you get. that is insane.

  JLi> decodeRegions($ridges,6,@mod3Regions); //(buttons, counter, array)

  JLi> sub decodeRegions {
  JLi> 	my ($what, $counter, @who) = @_;

and what if you want to pass in 2 arrays? learn about array refs before
you need them.

  JLi> 	for (my $j=1; $j<$counter; $j++) {

c syntax isn't perl either.

	foreach my $j ( 0 .. $counter - 1 ) {

  JLi> 	my $mask = 1 << $j-1;

don't need the -1 if your loop index is done correctly.


  JLi> 	$buttonSelected = $what & $mask;

no need for the temp variable mask or even the temp var buttonselected

  JLi> 	if ($buttonSelected != 0) {

	if ( $what & (1 << $j) ) {

  JLi> 	print $who[$j].", \n";

why two args to print? one will do and is much easier to read.

	print "$who[$j]\n";

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Sun, 17 Apr 2011 11:56:46 +0200
From: =?utf-8?B?RnLDqWTDqXJpYw==?= Perrin <fred.NO@SPAM.resel.fr>
Subject: Re: Help! How to pass array indexes to subroutine?
Message-Id: <kggbp05kxpd.fsf@pc-df-301.priv.enst-bretagne.fr>

"Uri Guttman" <uri@StemSystems.com> writes:
>>>>>> "JLi" == Joey@still Learning invalid <Joey@still_Learning.invalid> writes:
>   JLi> 	my $mask = 1 << $j-1;
>
> don't need the -1 if your loop index is done correctly.

To Joey's defence, he /is/ starting to look at @who's elements from 1,
not from 0, so one way or the other there will be a -1 or a +1 somewhere.

-- 
Frédéric Perrin -- http://tar-jx.bz


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

Date: Sun, 17 Apr 2011 10:48:53 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Help! How to pass array indexes to subroutine?
Message-Id: <slrniqm2m9.bae.tadmc@tadbox.sbcglobal.net>

Joey@still_Learning.invalid <Joey@still_Learning.invalid> wrote:
> Frédéric Perrin wrote:
>
>>"Joey@still_Learning.invalid" <Joey@still_Learning.invalid> writes:

>>> sub getValues($what, $who, 4) {
>>
>>You just invented some syntax, there.
>
> Actually, no. 


Actually, yes!


> It's the same syntax as javascript (except for the $), 


It is the same syntax with *different semantics* !

(i.e. in Perl it does not do the same thing as it does in JS)

(
    this is the "syntax" versus "semantics" distinction again,
    it appears that you have not yet learned that distinction.
    Try again. It is of profound importance in becoming a
    decent programmer.
)


> and
> Perl ignores the parameters. 


No it doesn't.

(and you should always enable warnings when developing Perl code!)


> I write as much js as I write in Perl and
> it's convenient to not have to change syntax rules if it's not essential.


Sacrificing maintainability on the altar of convenience is a mark
of a programmer that has not yet learned his trade.

Saving time when coding at the expense of spending more time in
maintenance is a bad trade-off.

When you come back to this code after 6 months, you will spend time
trying to figure out what the prototypes are for... only to discover
that using a prototype was not what you intended when you wrote it.


> sub decodeRegions {
> 	my ($what, $counter, @who) = @_;
> 	for (my $j=1; $j<$counter; $j++) {
> 	my $mask = 1 << $j-1;
> 	$buttonSelected = $what & $mask;
> 	if ($buttonSelected != 0) {
> 	print $who[$j].", \n";
> 	}
> 	}
> }


Something horrid has happened to your indenting.

That is bad for maintenance too...


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Sun, 17 Apr 2011 12:46:05 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Help! How to pass array indexes to subroutine?
Message-Id: <8739lgltbm.fsf@quad.sysarch.com>

>>>>> "FP" == Frédéric Perrin <fred.NO@SPAM.resel.fr> writes:

  FP> "Uri Guttman" <uri@StemSystems.com> writes:
  >>>>>>> "JLi" == Joey@still Learning invalid <Joey@still_Learning.invalid> writes:
  JLi> my $mask = 1 << $j-1;
  >> 
  >> don't need the -1 if your loop index is done correctly.

  FP> To Joey's defence, he /is/ starting to look at @who's elements from 1,
  FP> not from 0, so one way or the other there will be a -1 or a +1 somewhere.

then do that in the foreach part. much cleaner there than doing a -1
later.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3354
***************************************


home help back first fref pref prev next nref lref last post