perl dd

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

Hi,

I want to know if any module for "dd" in perl is available.

Any pointers will a great help

Thanks,
a b

--bcaec51b19510ebb24049f869613--
chillidba [ Mo, 28 März 2011 10:18 ] [ ID #2057215 ]

Re: perl dd

--0023541888d83e5bd0049f86d44a
Content-Type: text/plain; charset=UTF-8

On Mon, Mar 28, 2011 at 10:18 AM, a b <testabhi [at] gmail.com> wrote:

> Hi,
>
> I want to know if any module for "dd" in perl is available.
>
> Any pointers will a great help
>
> Thanks,
> a b
>

Have you tried having a look at search.cpan.org?
Oh, by the way what does dd stand for? Acronyms are great and all but unless
you are asking the guy next to you working with the same acronyms on a daily
basis it is unlikely that others will know what it is that you are talking
about.

Regards,

Rob

--0023541888d83e5bd0049f86d44a--
Rob Coops [ Mo, 28 März 2011 10:35 ] [ ID #2057216 ]

Re: perl dd

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

Hey Rob,


Yes, you are right
Thanks to mention this out.

I was referring to unix dd command. was wondering if we have any module
already available.

i didn't found on cpan

Thx
a b

On Mon, Mar 28, 2011 at 2:05 PM, Rob Coops <rcoops [at] gmail.com> wrote:

>
>
> On Mon, Mar 28, 2011 at 10:18 AM, a b <testabhi [at] gmail.com> wrote:
>
>> Hi,
>>
>> I want to know if any module for "dd" in perl is available.
>>
>> Any pointers will a great help
>>
>> Thanks,
>> a b
>>
>
> Have you tried having a look at search.cpan.org?
> Oh, by the way what does dd stand for? Acronyms are great and all but
> unless you are asking the guy next to you working with the same acronyms on
> a daily basis it is unlikely that others will know what it is that you are
> talking about.
>
> Regards,
>
> Rob
>

--bcaec51b19519562d8049f873ee5--
chillidba [ Mo, 28 März 2011 11:05 ] [ ID #2057217 ]

Re: perl dd

--20cf307f342073d5f8049f8766a6
Content-Type: text/plain; charset=UTF-8

I had a quick look but I can only see people making system calls using
system() or exec() etc... which sort of makes sense as there is no such
command on pretty much any system except for *nix systems. I think you might
simply have to write your own implementation or simply rely on system calls
to get this done. IT will mean though that you code will not be very
portable as it will only work on *nix systems and not on pretty much
anything else.

Regards,

Rob

On Mon, Mar 28, 2011 at 11:05 AM, a b <testabhi [at] gmail.com> wrote:

> Hey Rob,
>
>
> Yes, you are right
> Thanks to mention this out.
>
> I was referring to unix dd command. was wondering if we have any module
> already available.
>
> i didn't found on cpan
>
> Thx
> a b
>
> On Mon, Mar 28, 2011 at 2:05 PM, Rob Coops <rcoops [at] gmail.com> wrote:
>
>>
>>
>> On Mon, Mar 28, 2011 at 10:18 AM, a b <testabhi [at] gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I want to know if any module for "dd" in perl is available.
>>>
>>> Any pointers will a great help
>>>
>>> Thanks,
>>> a b
>>>
>>
>> Have you tried having a look at search.cpan.org?
>> Oh, by the way what does dd stand for? Acronyms are great and all but
>> unless you are asking the guy next to you working with the same acronyms on
>> a daily basis it is unlikely that others will know what it is that you are
>> talking about.
>>
>> Regards,
>>
>> Rob
>>
>
>

--20cf307f342073d5f8049f8766a6--
Rob Coops [ Mo, 28 März 2011 11:16 ] [ ID #2057218 ]

Re: perl dd

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

Thanks Rob

I too was thinking that way. Just in case if any one might have face this
issue and hence this email

Well if no module i will live with it for time being

Regards,
a b

On Mon, Mar 28, 2011 at 2:46 PM, Rob Coops <rcoops [at] gmail.com> wrote:

> I had a quick look but I can only see people making system calls using
> system() or exec() etc... which sort of makes sense as there is no such
> command on pretty much any system except for *nix systems. I think you might
> simply have to write your own implementation or simply rely on system calls
> to get this done. IT will mean though that you code will not be very
> portable as it will only work on *nix systems and not on pretty much
> anything else.
>
> Regards,
>
> Rob
>
>
> On Mon, Mar 28, 2011 at 11:05 AM, a b <testabhi [at] gmail.com> wrote:
>
>> Hey Rob,
>>
>>
>> Yes, you are right
>> Thanks to mention this out.
>>
>> I was referring to unix dd command. was wondering if we have any module
>> already available.
>>
>> i didn't found on cpan
>>
>> Thx
>> a b
>>
>> On Mon, Mar 28, 2011 at 2:05 PM, Rob Coops <rcoops [at] gmail.com> wrote:
>>
>>>
>>>
>>> On Mon, Mar 28, 2011 at 10:18 AM, a b <testabhi [at] gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I want to know if any module for "dd" in perl is available.
>>>>
>>>> Any pointers will a great help
>>>>
>>>> Thanks,
>>>> a b
>>>>
>>>
>>> Have you tried having a look at search.cpan.org?
>>> Oh, by the way what does dd stand for? Acronyms are great and all but
>>> unless you are asking the guy next to you working with the same acronyms on
>>> a daily basis it is unlikely that others will know what it is that you are
>>> talking about.
>>>
>>> Regards,
>>>
>>> Rob
>>>
>>
>>
>

--0016364992bf5a4b2a049f877c6c--
chillidba [ Mo, 28 März 2011 11:22 ] [ ID #2057219 ]

Re: perl dd

On Mon, Mar 28, 2011 at 05:22, a b <testabhi [at] gmail.com> wrote:
> Thanks Rob
>
> I too was thinking that way. Just in case if any one might have face this
> issue and hence this email
>
> Well if no module i will live with it for time being
snip

The Unix dd command is a swiss army knife of copying data, could you
narrow it down to what you want to use dd for? A simple
implementation would be

#!/usr/bin/perl

use strict;
use warnings;

die "usage: $0 infile outfile\n" unless [at] ARGV == 2;

open my $in, "<:raw", $ARGV[0]
or die "could not open $ARGV[0]: $!\n";
open my $out, ">:raw", $ARGV[1]
or die "could not open $ARGV[1]: $!\n";

local $/ = \4096; #read 4k at a time

print $out $_ while <$in>;



--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
chas.owens [ Mo, 28 März 2011 14:40 ] [ ID #2057221 ]

Re: perl dd

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

Hey Chas,

Thanks much for your reply. I actually want to have some more control over
this.

Thinking in way to initiate some in parallel also to get rid of ""OS""
specific things [if there]

thought of minimizing effort to run something which you suggested below. But
seems like, the only option in this galaxy :(

Thanks Everyone
Regards,
a b

On Mon, Mar 28, 2011 at 6:10 PM, Chas. Owens <chas.owens [at] gmail.com> wrote:

> On Mon, Mar 28, 2011 at 05:22, a b <testabhi [at] gmail.com> wrote:
> > Thanks Rob
> >
> > I too was thinking that way. Just in case if any one might have face this
> > issue and hence this email
> >
> > Well if no module i will live with it for time being
> snip
>
> The Unix dd command is a swiss army knife of copying data, could you
> narrow it down to what you want to use dd for? A simple
> implementation would be
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> die "usage: $0 infile outfile\n" unless [at] ARGV == 2;
>
> open my $in, "<:raw", $ARGV[0]
> or die "could not open $ARGV[0]: $!\n";
> open my $out, ">:raw", $ARGV[1]
> or die "could not open $ARGV[1]: $!\n";
>
> local $/ = \4096; #read 4k at a time
>
> print $out $_ while <$in>;
>
>
>
> --
> Chas. Owens
> wonkden.net
> The most important skill a programmer can have is the ability to read.
>

--0016368e2a87a6bc24049fa046b7--
chillidba [ Di, 29 März 2011 16:57 ] [ ID #2057266 ]

Re: perl dd

Hi,

On Tue, Mar 29, 2011 at 4:57 PM, a b <testabhi [at] gmail.com> wrote:
> Hey Chas,
>
> Thanks much for your reply. I actually want to have some more control over
> this.
>
> Thinking in way to initiate some in parallel also to get rid of ""OS""
> specific things [if there]
>
dd is really pretty limited if you want to use it as a IO benchmarking tool
and automate stuff with it via Perl.

Perhaps you want to look at more powerful IO load tools like IOzone.
As it happens, a quick google search tells me that IOzone actually has
some Perl modules to parse its output.

Good luck & best regards,
Filip

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Filip Sneppe [ Di, 29 März 2011 18:57 ] [ ID #2057267 ]

Re: perl dd

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

Thanks all!!

Can someone tell me if you have any experience in generating files
quickly(not sparse) in unix?

I want to generate millions of files under some directory

Thanks in Advance!

On Tue, Mar 29, 2011 at 10:27 PM, Filip Sneppe <filip.sneppe [at] gmail.com>wrote:

> Hi,
>
> On Tue, Mar 29, 2011 at 4:57 PM, a b <testabhi [at] gmail.com> wrote:
> > Hey Chas,
> >
> > Thanks much for your reply. I actually want to have some more control
> over
> > this.
> >
> > Thinking in way to initiate some in parallel also to get rid of ""OS""
> > specific things [if there]
> >
> dd is really pretty limited if you want to use it as a IO benchmarking tool
> and automate stuff with it via Perl.
>
> Perhaps you want to look at more powerful IO load tools like IOzone.
> As it happens, a quick google search tells me that IOzone actually has
> some Perl modules to parse its output.
>
> Good luck & best regards,
> Filip
>

--001636ed72fe93108e049fb17b7d--
chillidba [ Mi, 30 März 2011 13:28 ] [ ID #2057368 ]

Re: perl dd

> Thanks all!!
>
> Can someone tell me if you have any experience in generating files
> quickly(not sparse) in unix?
>
> I want to generate millions of files under some directory
>

This will generate 10000 files in less than a second. They are 0 size,
so just write something into them if you don't wont zero sized files


#!/usr/bin/perl
use strict;
my $file =3D "/some/where/writeable/a1";
my $j =3D 0;
for ( my $i =3D 1 ; $i < 10000 ; $i++ ) {
my $dts =3D $j++;
open( my $FH, ">", "$file$dts" ) or die "cant open file$dts!";
close $FH;
}



--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Owen [ Do, 31 März 2011 00:55 ] [ ID #2057419 ]

Re: perl dd

>>>>> "O" == Owen <rcook [at] pcug.org.au> writes:

O> This will generate 10000 files in less than a second. They are 0 size,
O> so just write something into them if you don't wont zero sized files

might as well clean this up.

O> #!/usr/bin/perl
O> use strict;
O> my $file = "/some/where/writeable/a1";

O> my $j = 0;

O> for ( my $i = 1 ; $i < 10000 ; $i++ ) {

classic c loop. don't do c loops unless you must. they are not very
perlish. perl loops are cleaner and faster:

foreach my $i ( 1 .. 10000 ) {

O> my $dts = $j++;

why don't you just use $j? or even $i?? change the loop and use $dts.

foreach my $dts ( 0 .. 99999 ) {

O> open( my $FH, ">", "$file$dts" ) or die "cant open file$dts!";
O> close $FH;

and using File::Slurp cleans that up too:

use File::Slurp ;
write_file "$file$dts", '' ;

or even:

write_file "$file$_", '' for 0 .. 99999 ;

that allows for data instead of '' as well.

uri

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

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Uri Guttman [ Do, 31 März 2011 01:19 ] [ ID #2057421 ]

Re: perl dd

Uri Guttman wrote:
>>>>>> "O" == Owen<rcook [at] pcug.org.au> writes:
>
> O> This will generate 10000 files in less than a second. They are 0 size,
> O> so just write something into them if you don't wont zero sized files
>
> might as well clean this up.
>
> O> #!/usr/bin/perl
> O> use strict;
> O> my $file = "/some/where/writeable/a1";
>
> O> my $j = 0;
>
> O> for ( my $i = 1 ; $i< 10000 ; $i++ ) {
>
> classic c loop. don't do c loops unless you must. they are not very
> perlish. perl loops are cleaner and faster:
>
> foreach my $i ( 1 .. 10000 ) {

ITYM:

foreach my $i ( 1 .. 9999 ) {




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
jwkrahn [ Do, 31 März 2011 02:16 ] [ ID #2057422 ]

Re: perl dd

>>>>> "JWK" == John W Krahn <jwkrahn [at] shaw.ca> writes:

JWK> Uri Guttman wrote:
>> foreach my $i ( 1 .. 10000 ) {

JWK> ITYM:

JWK> foreach my $i ( 1 .. 9999 ) {

yes. and i also did 1 .. 99999 later on. numerical typos is my excuse.

uri

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

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Uri Guttman [ Do, 31 März 2011 02:22 ] [ ID #2057423 ]

Re: perl dd

Hi Uri,

On Thursday 31 Mar 2011 01:19:15 Uri Guttman wrote:
> >>>>> "O" == Owen <rcook [at] pcug.org.au> writes:
> O> This will generate 10000 files in less than a second. They are 0 size,
> O> so just write something into them if you don't wont zero sized files
>
> might as well clean this up.
>
> O> #!/usr/bin/perl
> O> use strict;
> O> my $file = "/some/where/writeable/a1";
>
> O> my $j = 0;
>
> O> for ( my $i = 1 ; $i < 10000 ; $i++ ) {
>
> classic c loop. don't do c loops unless you must. they are not very
> perlish. perl loops are cleaner and faster:
>
> foreach my $i ( 1 .. 10000 ) {
>

OK, one problem I can see here is the "magic number" / "magic constant" coding
smell:

* http://perl-begin.org/tutorials/bad-elements/#magic_numbers

*
http://en.wikipedia.org/wiki/Magic_number_%28programming%29# Unnamed_numerical_constants

The best way to overcome it is to assign it to a named constant, i.e:
"my $num_written_files = 10_000;" or with "use constant" or Readonly.pm (and I
recall an alternative for that). It also seems to appear more than one time in
the code which indicates some small amount of duplicate code (what if you'd
like to add it later).

Also, Larry Wall has allowed Perl 5 numeric constants to contain underscore so
you can write 10**9 as 1_000_000_000 instead of 1000000000 which is much less
readable and also more error-prone. (Larry Wall)++ .

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
My Public Domain Photos - http://www.flickr.com/photos/shlomif/

And the top story for today: wives live longer than husbands because they are
not married to women.
-- Colin Mochrie in "Who's Line is it, Anyway?"

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shlomi Fish [ Do, 31 März 2011 12:07 ] [ ID #2057424 ]

Re: perl dd

On Thu, 31 Mar 2011 12:07:41 +0200, Shlomi Fish wrote:
> Also, Larry Wall has allowed Perl 5 numeric constants to contain
> underscore so you can write 10**9 as 1_000_000_000 instead of 100000000=
0
> which is much less readable and also more error-prone. (Larry Wall)++ .

1E9 seems to capture your intention even better :-)

--
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=3D0137001274
http://www.oreillyschool.com/courses/perl3/

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Peter Scott [ Do, 31 März 2011 16:54 ] [ ID #2057425 ]

Re: perl dd

On Thursday 31 Mar 2011 16:54:14 Peter Scott wrote:
> On Thu, 31 Mar 2011 12:07:41 +0200, Shlomi Fish wrote:
> > Also, Larry Wall has allowed Perl 5 numeric constants to contain
> > underscore so you can write 10**9 as 1_000_000_000 instead of 1000000000
> > which is much less readable and also more error-prone. (Larry Wall)++ .
>
> 1E9 seems to capture your intention even better :-)

Heh. :-). just for the record:

1. 1_000_000_000 was just for the sake of the example. It could also be:
2_435_279_145 or something else that is arbitrary.

2. The problem with 1E9 is that I think it's a floating point number (though
Perl 5 may have some intelligence there). Not sure it matterns a lot for Perl
but if you do something like 1.27E9 you may get weird side-effects due to:

http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_go ldberg.html

(Oracle++ for fixing the old link from docs.sun.com after it was broken.)

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/

<Botje> Khisanth =~ s/must sleep/must give Botje all my money/ .
-- Freenode's #perl

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shlomi Fish [ Fr, 01 April 2011 09:51 ] [ ID #2057444 ]

Re: perl dd

On Fri, 01 Apr 2011 10:51:58 +0300, Shlomi Fish wrote:
> 2. The problem with 1E9 is that I think it's a floating point number
> (though Perl 5 may have some intelligence there). Not sure it matterns =
a
> lot for Perl but if you do something like 1.27E9 you may get weird
> side-effects due to:

Yup, anything in scientific notation becomes floating point, but I doubt
it's going to matter in the case of 1E9:

$ perl -MDevel::Peek -e 'Dump($_) for 1E9, 1000000000, 1E2'
SV =3D NV(0x8a4aee8) at 0x8a367b8
REFCNT =3D 2
FLAGS =3D (NOK,READONLY,pNOK)
NV =3D 1000000000
SV =3D IV(0x8a367c4) at 0x8a367c8
REFCNT =3D 2
FLAGS =3D (IOK,READONLY,pIOK)
IV =3D 1000000000
SV =3D NV(0x8a4aef0) at 0x8a367d8
REFCNT =3D 2
FLAGS =3D (NOK,READONLY,pNOK)
NV =3D 100


--
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=3D0137001274
http://www.oreillyschool.com/courses/perl3/

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Peter Scott [ Sa, 02 April 2011 17:26 ] [ ID #2057493 ]
Perl » gmane.comp.lang.perl.beginners » perl dd

Vorheriges Thema: Re: Perl Hash Comparison and concatenate result from %hash2 comparedto %hash1 into %hash3
Nächstes Thema: parsing a delimited file