Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Can't get past 'use strict' :(

Reply
Thread Tools

Can't get past 'use strict' :(

 
 
Karlo Lozovina
Guest
Posts: n/a
 
      12-16-2004
"Peter Wyzl" <(E-Mail Removed)> wrote in
news:ayewd.74895$(E-Mail Removed):

> It won't compile even without 'use strict'. You can't declare a
> slice of an array like that, you need to declare the whole array
> and then assign to the slices.


I know - looking at that code day after, and I seem like an idiot
.

> However, a better, or more Perlish way to do that would be to take
> advantage of some of the majic offered by the <> operator in array
> context and read the whole file into the array in one step.
> my @dir_list = <DIRLIST>;


Wow! Didn't know Perl can do that. It rocks, thanks.

> You can then chomp() the array without having to chomp every
> element as you read it...
> chomp @dir_list;


Didn't now I can do that, either . Guess I'll have to finish
reading Programming Perl before beginning another Perl project.

Anyway, thanks a lot Peter, you've been most helpfull.

--
Karlo Lozovina - Mosor
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      12-16-2004
Robin <(E-Mail Removed)> wrote:
> "Karlo Lozovina" <_karlo_@_mosor.net_> wrote in message
> news:Xns95C0B356F954Bkarlomosornet@130.133.1.4...



>> while(my $line = <DIRLIST>) {
>> my $dir_list[$i] = $line;
>> chomp($dir_list[$i]);
>> $i++;
>> }



[ snip quoted .sig, you aren't supposed to do that you know ]


> actually, your code looks pretty tight.



Nonsense alert!!


Doing explicit indexing when explicit indexing is not required
by the algorithm is "error prone" rather than "tight".

chomp(@dir_list = <DIRLIST>);

Does the same thing, and seems much closer to what a reasonable
person might call "tight".


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      12-16-2004
"Robin" <webmaster @ infusedlight.net> wrote in news:WY6dne9XT_dMyFzcRVn-
(E-Mail Removed):

>
> "Karlo Lozovina" <_karlo_@_mosor.net_> wrote in message
> news:Xns95C0B356F954Bkarlomosornet@130.133.1.4...


>> while(my $line = <DIRLIST>) {
>> my $dir_list[$i] = $line;
>> chomp($dir_list[$i]);


....

>> syntax error at ./backup.pl line 24, near "$dir_list["


>> --
>> _______ Karlo Lozovina - Mosor
>> | | |.-----.-----.
>> | || _ | _ | Na osami blizu mora, dok se sunce zemlji smije
>> |__|_|__||_____|_____| Balun gledat, za njin letit...

>
> actually, your code looks pretty tight.
> -Robin


For various values of tight.

How can something that is reported by perl to be a syntax error be
considered "tight".

Oh, by the way, please take a look at the posting guidelines and definitely
do not quote people's signatures.

Sinan.
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      12-16-2004
"Peter Wyzl" <(E-Mail Removed)> wrote in
news:ayewd.74895$(E-Mail Removed):

> "Karlo Lozovina" <_karlo_@_mosor.net_> wrote in message
> news:Xns95C0B356F954Bkarlomosornet@130.133.1.4...
>: Here I go again: the following code:
>:
>: while(my $line = <DIRLIST>) {
>: my $dir_list[$i] = $line;
>: chomp($dir_list[$i]);
>: $i++;
>: }
>
> It won't compile even without 'use strict'. You can't declare a slice
> of an array like that, you need to declare the whole array and then
> assign to the slices.


Minor correction: $dir_list[$i] is not a slice but an array element.

Sinan
 
Reply With Quote
 
frans abels
Guest
Posts: n/a
 
      12-16-2004
On Thu, 16 Dec 2004 10:31:12 +0100, Robin wrote:


> "Karlo Lozovina" <_karlo_@_mosor.net_> wrote in message
> news:Xns95C0B356F954Bkarlomosornet@130.133.1.4...
>> Here I go again: the following code:
>>
>> while(my $line = <DIRLIST>) {
>> my $dir_list[$i] = $line;
>> chomp($dir_list[$i]);
>> $i++;
>> }
>>
>> produces this error:
>>
>> syntax error at ./backup.pl line 24, near "$dir_list["
>>


> actually, your code looks pretty tight. -Robin


I don't know what that means,
but it has a syntax error...
my is not allowed with array-element assignments.
If you want to code this way and not the most efficient way
it should be:

my @dir_list;
while(my $line = <DIRLIST>) {
$dir_list[$i] = $line;
chomp($dir_list[$i]);
$i++;
}
 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      12-16-2004


A. Sinan Unur wrote:

> "Robin" <webmaster @ infusedlight.net> wrote in news:WY6dne9XT_dMyFzcRVn-
> (E-Mail Removed):
>>
>>actually, your code looks pretty tight.

>
> For various values of tight.


The only one I think he means is is meaning #6 as defined in
Merriam-Webster Online dictionary.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot get past Object Reference Error danielle.m.manning@gmail.com ASP .Net 1 03-28-2006 11:43 PM
Cannot get past Object Reference Error danielle.m.manning@gmail.com ASP .Net 2 03-28-2006 11:17 PM
I get declaration error - When I past it on the next line and comments out the old, the syntax works... why?!? knutivar ASP .Net 2 12-09-2004 05:45 PM
How do you get rid of past newsgroups Monica Computer Support 7 04-24-2004 07:50 PM
Suggestion for HTML Editor to get past the crappy IDE one Lloyd Sheen ASP .Net 13 01-25-2004 10:42 PM



Advertisments