Access files in a folder

Access files in a folder

am 31.07.2011 22:52:24 von Emeka

--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--

Re: Access files in a folder

am 31.07.2011 22:57:18 von Shawn H Corey

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 @ARGV = glob( '*.pl' );
while( <> ){
print $_;
}
}

See:
perldoc -f glob
perldoc -f local
perldoc perlvar and search for /\@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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Access files in a folder

am 31.07.2011 23:02:36 von Shawn Wilson

--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" 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--

Re: Access files in a folder

am 01.08.2011 00:02:14 von Rob Dixon

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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Access files in a folder

am 01.08.2011 00:23:59 von Emeka

--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 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--

Re: Access files in a folder

am 01.08.2011 00:44:01 von Emeka

--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 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 @ARGV = glob( '*.pl' );
> while( <> ){
> print $_;
> }
> }
>
> See:
> perldoc -f glob
> perldoc -f local
> perldoc perlvar and search for /\@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@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>


--
*Satajanus Nig. Ltd


*

--bcaec5314a9544add904a965408c--

Re: Access files in a folder

am 01.08.2011 01:15:28 von Shawn H Corey

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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/