Access files in a folder

--000e0cd247b016a6fb04a963b13c
Content-Type: text/plain; charset=ISO-8859-1

Hello All,


I wanted to do this ...

while(<*.pl>){
print $_;
}


I got "BEGIN failed--compilation"

Am I using something that is old?


Emeka

--
*Satajanus Nig. Ltd


*

--000e0cd247b016a6fb04a963b13c--
Emeka [ So, 31 Juli 2011 22:52 ] [ ID #2062831 ]

Re: Access files in a folder

On 11-07-31 04:52 PM, Emeka wrote:
> Hello All,
>
>
> I wanted to do this ...
>
> while(<*.pl>){
> print $_;
> }
>
>
> I got "BEGIN failed--compilation"
>
> Am I using something that is old?

Try:

{
local [at] ARGV = glob( '*.pl' );
while( <> ){
print $_;
}
}

See:
perldoc -f glob
perldoc -f local
perldoc perlvar and search for /\ [at] ARGV/


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

"Make something worthwhile." -- Dear Hunter

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shawn H Corey [ So, 31 Juli 2011 22:57 ] [ ID #2062832 ]

Re: Access files in a folder

--000325579d928bbfcf04a963d5e2
Content-Type: text/plain; charset=ISO-8859-1

If you want that in a script, use File::Find and open each file and pass the
file handle.
On Jul 31, 2011 4:53 PM, "Emeka" <emekamicro [at] gmail.com> wrote:
> Hello All,
>
>
> I wanted to do this ...
>
> while(<*.pl>){
> print $_;
> }
>
>
> I got "BEGIN failed--compilation"
>
> Am I using something that is old?
>
>
> Emeka
>
> --
> *Satajanus Nig. Ltd
>
>
> *

--000325579d928bbfcf04a963d5e2--
Shawn Wilson [ So, 31 Juli 2011 23:02 ] [ ID #2062833 ]

Re: Access files in a folder

On 31/07/2011 21:52, Emeka wrote:
> Hello All,
>
> I wanted to do this ...
>
> while(<*.pl>){
> print $_;
> }
>
>
> I got "BEGIN failed--compilation"
>
> Am I using something that is old?

There is nothing wrong with that. Please show your complete program -
there must be something else in the file that is causing the compilation
error.

Rob

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Rob Dixon [ Mo, 01 August 2011 00:02 ] [ ID #2062834 ]

Re: Access files in a folder

--000e0cd152249b89b304a964f8c6
Content-Type: text/plain; charset=ISO-8859-1

Thanks Rob ... It worked. Shawn thanks so much.

I found out that the problem was from my little box Nanonote... It has a
light weight Perl. When I switched to real thing it worked.

Emeka

On Sun, Jul 31, 2011 at 11:02 PM, Rob Dixon <rob.dixon [at] gmx.com> wrote:

> On 31/07/2011 21:52, Emeka wrote:
>
>> Hello All,
>>
>> I wanted to do this ...
>>
>> while(<*.pl>){
>> print $_;
>> }
>>
>>
>> I got "BEGIN failed--compilation"
>>
>> Am I using something that is old?
>>
>
> There is nothing wrong with that. Please show your complete program -
> there must be something else in the file that is causing the compilation
> error.
>
> Rob
>



--
*Satajanus Nig. Ltd


*

--000e0cd152249b89b304a964f8c6--
Emeka [ Mo, 01 August 2011 00:23 ] [ ID #2062858 ]

Re: Access files in a folder

--bcaec5314a9544add904a965408c
Content-Type: text/plain; charset=ISO-8859-1

Shawn,

Yours will print the content of each file... while mine will list only their
names.

Emeka

On Sun, Jul 31, 2011 at 9:57 PM, Shawn H Corey <shawnhcorey [at] gmail.com>wrote:

> On 11-07-31 04:52 PM, Emeka wrote:
>
>> Hello All,
>>
>>
>> I wanted to do this ...
>>
>> while(<*.pl>){
>> print $_;
>> }
>>
>>
>> I got "BEGIN failed--compilation"
>>
>> Am I using something that is old?
>>
>
> Try:
>
> {
> local [at] ARGV = glob( '*.pl' );
> while( <> ){
> print $_;
> }
> }
>
> See:
> perldoc -f glob
> perldoc -f local
> perldoc perlvar and search for /\ [at] ARGV/
>
>
> --
> Just my 0.00000002 million dollars worth,
> Shawn
>
> Confusion is the first step of understanding.
>
> Programming is as much about organization and communication
> as it is about coding.
>
> The secret to great software: Fail early & often.
>
> Eliminate software piracy: use only FLOSS.
>
> "Make something worthwhile." -- Dear Hunter
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
> For additional commands, e-mail: beginners-help [at] perl.org
> http://learn.perl.org/
>
>
>


--
*Satajanus Nig. Ltd


*

--bcaec5314a9544add904a965408c--
Emeka [ Mo, 01 August 2011 00:44 ] [ ID #2062859 ]

Re: Access files in a folder

On 11-07-31 06:44 PM, Emeka wrote:
> Yours will print the content of each file... while mine will list only their
> names.
>

Yes, sometimes people want the contents printed but end up printing the
list. I wasn't sure what you wanted and since your version looked good
for printing the list, I showed how to print the contents.


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

"Make something worthwhile." -- Dear Hunter

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shawn H Corey [ Mo, 01 August 2011 01:15 ] [ ID #2062860 ]
Perl » gmane.comp.lang.perl.beginners » Access files in a folder

Vorheriges Thema: Any suggestion on how to "improve" this code? Malformed braces
Nächstes Thema: End-of-Marker