Home > Archive > PERL Beginners > October 2005 > extract zip file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Hridyesh Pant 2005-10-25, 3:55 am |
| Hi All,
How to extract zip file using perl program...
Thanks
Hridyesh
| |
| Chris Devers 2005-10-25, 3:55 am |
| On Tue, 25 Oct 2005, Pant, Hridyesh wrote:
> How to extract zip file using perl program...
Write the program, then run it.
Have you tried writing it yet?
Have you tried searching CPAN for helpful modules?
--
Chris Devers
| |
| Tommy Nordgren 2005-10-25, 3:55 am |
|
Oct 25, 2005 kl. 6:21 AM skrev Pant, Hridyesh:
> Hi All,
> How to extract zip file using perl program...
>
> Thanks
> Hridyesh
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
system '/usr/bin/unzip',@OPTIONS,$zipfile;
-------------------------------------
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
tommy.nordgren@chello.se
| |
| Hridyesh Pant 2005-10-25, 3:55 am |
| Thanks..
Now I want to change the string in file.
orgtext=3D"C:\\test";
newtext=3D"/bin/old";
I tired $intext =3D~ s/$orgtext/$newtext/ms; but this is not working..
Any help..
Regards
Hridyesh
-----Original Message-----
From: Chris Devers [mailto:cdevers@pobox.com]=20
Sent: 25 October 2005 10:21
To: Pant, Hridyesh
Cc: beginners@perl.org
Subject: Re: extract zip file
On Tue, 25 Oct 2005, Pant, Hridyesh wrote:
> How to extract zip file using perl program...
Write the program, then run it.
Have you tried writing it yet?
Have you tried searching CPAN for helpful modules?
--=20
Chris Devers
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| John Doe 2005-10-25, 3:55 am |
| Pant, Hridyesh am Dienstag, 25. Oktober 2005 08.08:
> Thanks..
> Now I want to change the string in file.
> orgtext="C:\\test";
> newtext="/bin/old";
> I tired $intext =~ s/$orgtext/$newtext/ms; but this is not working..
Wrong modifiers /ms. See
perldoc perlre
perldoc perlretut
joe
| |
| Hridyesh Pant 2005-10-25, 6:56 pm |
| But the same is working if I am using=20
orgtext=3D"Hello";
newtext=3D"world";
I tired $intext =3D~ s/$orgtext/$newtext/ms; but this is not working..
The only problem is string like "C:\\test".
Hridyesh...
-----Original Message-----
From: John Doe [mailto:security.department@tele2.ch]=20
Sent: 25 October 2005 14:08
To: beginners@perl.org
Subject: Re: extract zip file
Pant, Hridyesh am Dienstag, 25. Oktober 2005 08.08:
> Thanks..
> Now I want to change the string in file.
> orgtext=3D"C:\\test";
> newtext=3D"/bin/old";
> I tired $intext =3D~ s/$orgtext/$newtext/ms; but this is not working..
Wrong modifiers /ms. See
perldoc perlre
perldoc perlretut
joe
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Paul Lalli 2005-10-25, 6:56 pm |
| Hridyesh Pant wrote:
> But the same is working if I am using
>
> orgtext="Hello";
> newtext="world";
> I tired $intext =~ s/$orgtext/$newtext/ms; but this is not working..
>
> The only problem is string like "C:\\test".
Can you post a short-but-complete script that demonstrates how this is
"not working"? Something we can run to see for ourselves, rather than
just taking your word that you're doing everything correctly?
Paul Lalli
| |
| John Doe 2005-10-25, 6:56 pm |
| Pant, Hridyesh am Dienstag, 25. Oktober 2005 11.04:
> But the same is working if I am using
> orgtext="Hello";
> newtext="world";
> I tired $intext =~ s/$orgtext/$newtext/ms; but this is not working..
> The only problem is string like "C:\\test".
I was not well prepared with my last answer.
First, the combination of
m: Treat string as multiple lines
and
s: Treat string as single line
is still contradictory.
But your problem comes from the string 'C:\\test' containing backslashes.
When you say f.e.
my $str="C:\\test\a\b";
you get 'C:\test' in $str because of the double quotes the backslashes get
interpolated. See perldoc perlop.
So, use single quotes.
Then, in your regex, use \Q and \E to disable pattern metacharacters. See
perldoc perlre.
$orgtext='C:\\test';
$intext =~ s/\Q$orgtext\E/$newtext/gs;
Joe
> -----Original Message-----
> From: John Doe [mailto:security.department@tele2.ch]
> Sent: 25 October 2005 14:08
> To: beginners@perl.org
> Subject: Re: extract zip file
>
> Pant, Hridyesh am Dienstag, 25. Oktober 2005 08.08:
>
> Wrong modifiers /ms. See
>
> perldoc perlre
> perldoc perlretut
>
> joe
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Hridyesh Pant 2005-10-25, 6:56 pm |
| Thanks a lot john...
-----Original Message-----
From: John Doe [mailto:security.department@tele2.ch]=20
Sent: 25 October 2005 16:20
To: beginners@perl.org
Subject: Re: extract zip file
Pant, Hridyesh am Dienstag, 25. Oktober 2005 11.04:
> But the same is working if I am using
> orgtext=3D"Hello";
> newtext=3D"world";
> I tired $intext =3D~ s/$orgtext/$newtext/ms; but this is not working..
> The only problem is string like "C:\\test".
I was not well prepared with my last answer.
First, the combination of=20
m: Treat string as multiple lines
and
s: Treat string as single line
is still contradictory.
But your problem comes from the string 'C:\\test' containing
backslashes.
When you say f.e.
my $str=3D"C:\\test\a\b";
you get 'C:\test' in $str because of the double quotes the backslashes
get=20
interpolated. See perldoc perlop.
So, use single quotes.
Then, in your regex, use \Q and \E to disable pattern metacharacters.
See=20
perldoc perlre.
$orgtext=3D'C:\\test';
$intext =3D~ s/\Q$orgtext\E/$newtext/gs;=20
=09
Joe
> -----Original Message-----
> From: John Doe [mailto:security.department@tele2.ch]
> Sent: 25 October 2005 14:08
> To: beginners@perl.org
> Subject: Re: extract zip file
>
> Pant, Hridyesh am Dienstag, 25. Oktober 2005 08.08:
working..[color=darkred]
>
> Wrong modifiers /ms. See
>
> perldoc perlre
> perldoc perlretut
>
> joe
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Paul Lalli 2005-10-25, 6:56 pm |
| John Doe wrote:
> I was not well prepared with my last answer.
>
> First, the combination of
> m: Treat string as multiple lines
> and
> s: Treat string as single line
> is still contradictory.
No, they're not at all contradictory. Only their mnemonics are
contradictory. The /s modifier allows '.' to match a newline
character, while the /m modifier allows ^ and $ to match after and
before newline characters, in addition to just at the beginning and end
of the string.
Not only is it perfectly reasonable to use both /m and /s in the same
regexp, some (notably the author of _Perl Best Practices_, Damian
Conway) would suggest *always* using both modifiers.
Paul Lalli
| |
| John W. Krahn 2005-10-25, 6:56 pm |
| John Doe wrote:
> Pant, Hridyesh am Dienstag, 25. Oktober 2005 11.04:
>
> I was not well prepared with my last answer.
>
> First, the combination of
> m: Treat string as multiple lines
> and
> s: Treat string as single line
> is still contradictory.
/m defines how the anchors ^ and $ behave and /s defines how the . behaves so
they are not contradictory.
John
--
use Perl;
program
fulfillment
| |
| Wiggins d'Anconia 2005-10-26, 6:56 pm |
| Tommy Nordgren wrote:
>
> Oct 25, 2005 kl. 6:21 AM skrev Pant, Hridyesh:
>
>
> system '/usr/bin/unzip',@OPTIONS,$zipfile;
>
Time for me to rant about how the above is unacceptable for anything
other than a one off script. Shelling out using 'system' or backticks is
a last resort and should be used with care and the proper precautions
taken. The above lacks proper error handling, security safe guards, and
is inefficient and non-portable.
So the ML archives for further discussion of how to properly shell out...
http://danconia.org
| |
| Tommy Nordgren 2005-10-26, 6:56 pm |
|
Oct 26, 2005 kl. 7:56 PM skrev Wiggins d'Anconia:
> Tommy Nordgren wrote:
>
>
> Time for me to rant about how the above is unacceptable for anything
> other than a one off script. Shelling out using 'system' or
> backticks is
> a last resort and should be used with care and the proper precautions
>
Calling system with multiple paramaters don't 'shell out' as you call
it.'
It launches the tool in question directly, bypassing the shell entirely.
The main security concern of calling accientally a trojan horse
earlier in
the users path, don't apply when using the array form of system, with an
absolute search path
> taken. The above lacks proper error handling, security safe guards,
> and
> is inefficient and non-portable.
>
> So the ML archives for further discussion of how to properly shell
> out...
>
> http://danconia.org
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
-------------------------------------
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
tommy.nordgren@chello.se
| |
| Wiggins d'Anconia 2005-10-26, 6:56 pm |
| Tommy Nordgren wrote:
>
> Oct 26, 2005 kl. 7:56 PM skrev Wiggins d'Anconia:
>
>
> Calling system with multiple paramaters don't 'shell out' as you call it.'
> It launches the tool in question directly, bypassing the shell entirely.
> The main security concern of calling accientally a trojan horse earlier in
> the users path, don't apply when using the array form of system, with an
> absolute search path
>
Ok, fork/exec'ing, technically you are correct, the shell doesn't get a
chance to re-interpret the command line. You are also correct that you
avoid a trojan horse when someone places something earlier in the path,
of course there is nothing to say that /usr/bin/unzip isn't a trojan
horse itself, assuming it exists at all. Regardless the above code still
doesn't catch a missing executable, no permissions to run said
executable, or errors thrown by that executable, or on the flip side
that it was actually successful. Though I haven't benchmarked it, for
common practices shelling out is generally also slower than its native
Perl bretheren, and of course portability falls all to pieces.
So for proper applications something like Archive::Zip would be
significantly better from interface, security, portability, and
efficiency standpoints.
http://danconia.org
>
>
> -------------------------------------
> This sig is dedicated to the advancement of Nuclear Power
> Tommy Nordgren
> tommy.nordgren@chello.se
>
>
>
>
| |
| Wagner, David --- Senior Programmer Analyst --- WG 2005-10-26, 6:56 pm |
| Wiggins d'Anconia wrote:[color=darkred]
> Tommy Nordgren wrote:
Use the Perl Modules:
Use Archive::Zip::Tree and
Archive::Zip qw( :ERROR_CODES, :CONSTANTS )
I have a two scripts which I run every couple of w s to move data from o=
ne folder to another depending on whehter it is a daily, w ly or monthly =
process. After the first script completes, I run my second one which genera=
tes arhives for the data using the date for a particular files as the arhiv=
e. After I have archive everything, I then make a second pass verifying tha=
t the count in the arhive and what I thought I was archiving are the same. =
As I am doing this then I delete the source files. I have anywhere from 15=
0 to 250 meg of data arhived from my processing.
I never shell out and it has been running a number of years with no proble=
ms. Under the current Windows XP, you can enter the arhive like it was fol=
der and then pull if necessary any files you need.
Wags ;)[color=darkred]
>=20
> Ok, fork/exec'ing, technically you are correct, the shell doesn't get
> a chance to re-interpret the command line. You are also correct that
> you avoid a trojan horse when someone places something earlier in the
> path, of course there is nothing to say that /usr/bin/unzip isn't a
> trojan horse itself, assuming it exists at all. Regardless the above
> code still doesn't catch a missing executable, no permissions to run
> said executable, or errors thrown by that executable, or on the flip
> side that it was actually successful. Though I haven't benchmarked
> it, for common practices shelling out is generally also slower than
> its native Perl bretheren, and of course portability falls all to
> pieces.=20
>=20
> So for proper applications something like Archive::Zip would be
> significantly better from interface, security, portability, and
> efficiency standpoints.
>=20
> http://danconia.org
>=20
****************************************
***************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************
***************
|
|
|
|
|