FAQ
Hi,

It is actually very enlightening to read all the post
on this list. Most of the stuff actually goes over my head as
I have no need/knowledge of CGI or dbase. Just some text processing.

I am new to Programming/Perl (chapter 5 "Learning Perl").
I also read a little about 'system() & exec().

This is my first actual 'useful' Perl script!!
I had written this as a Bash script then converted it to Perl.

--code--

#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

my ($A, @B, @C, $D);

$A = 'http://abc.com/texts/files/getthisfile_';

# For files that are numbered by 01.txt
# Also can append a '0' to $A & still use @C
@B = qw { 01 02 03 04 05 06 07 08 09 10 };

# For files that are numbered by 1.txt
@C = (1..10);

$D = '.txt';

foreach my $i (@C) {
system 'wget', "${A}${i}${D}"; # I know wget can read from a file.
# say "${A}${i}${D}"; # say "$A$i$D"; # Which is correct? both work!
}

--code--

Is there a better way to write this without modules?
OR is it just too simple & just fine written this way?

Search Discussions

  • Jenda Krynicky at Jun 11, 2009 at 1:07 pm
    From: "raphael()" <raphael.japh@gmail.com>
    It is actually very enlightening to read all the post
    on this list. Most of the stuff actually goes over my head as
    I have no need/knowledge of CGI or dbase. Just some text processing.

    I am new to Programming/Perl (chapter 5 "Learning Perl").
    I also read a little about 'system() & exec().

    This is my first actual 'useful' Perl script!!
    I had written this as a Bash script then converted it to Perl.

    --code--

    #!/usr/bin/perl

    use 5.010;
    apart from the (pretty useles say()) there is nothing 5.10 specific
    in the code. I do think say() is not something I would want to make
    my scripts incompatible with older perls for.
    use strict;
    use warnings;

    my ($A, @B, @C, $D);
    Do use meaningful variable names! And declare them together with the
    definition, not upfront.
    $A = 'http://abc.com/texts/files/getthisfile_';

    # For files that are numbered by 01.txt
    # Also can append a '0' to $A & still use @C
    @B = qw { 01 02 03 04 05 06 07 08 09 10 };
    Have a look at spritf().
    # For files that are numbered by 1.txt
    @C = (1..10);

    $D = '.txt';

    foreach my $i (@C) {
    system 'wget', "${A}${i}${D}"; # I know wget can read from a file.
    # say "${A}${i}${D}"; # say "$A$i$D"; # Which is correct? both work!
    }

    --code--

    Is there a better way to write this without modules?
    OR is it just too simple & just fine written this way?
    Jenda

    ===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
    When it comes to wine, women and song, wizards are allowed
    to get drunk and croon as much as they like.
    -- Terry Pratchett in Sourcery
  • John W. Krahn at Jun 11, 2009 at 2:54 pm

    Jenda Krynicky wrote:
    From: "raphael()" <raphael.japh@gmail.com>
    It is actually very enlightening to read all the post
    on this list. Most of the stuff actually goes over my head as
    I have no need/knowledge of CGI or dbase. Just some text processing.

    I am new to Programming/Perl (chapter 5 "Learning Perl").
    I also read a little about 'system() & exec().

    This is my first actual 'useful' Perl script!!
    I had written this as a Bash script then converted it to Perl.

    --code--

    #!/usr/bin/perl

    use 5.010;
    apart from the (pretty useles say()) there is nothing 5.10 specific
    in the code. I do think say() is not something I would want to make
    my scripts incompatible with older perls for.
    use strict;
    use warnings;

    my ($A, @B, @C, $D);
    Do use meaningful variable names! And declare them together with the
    definition, not upfront.
    $A = 'http://abc.com/texts/files/getthisfile_';

    # For files that are numbered by 01.txt
    # Also can append a '0' to $A & still use @C
    @B = qw { 01 02 03 04 05 06 07 08 09 10 };
    Have a look at spritf().
    $ perldoc -f spritf
    No documentation for perl function `spritf' found

    ;-(


    John
    --
    Those people who think they know everything are a great
    annoyance to those of us who do. -- Isaac Asimov
  • Jenda Krynicky at Jun 11, 2009 at 7:31 pm
    From: "John W. Krahn" <jwkrahn@shaw.ca>
    Jenda Krynicky wrote:
    From: "raphael()" <raphael.japh@gmail.com>
    It is actually very enlightening to read all the post
    on this list. Most of the stuff actually goes over my head as
    I have no need/knowledge of CGI or dbase. Just some text processing.

    I am new to Programming/Perl (chapter 5 "Learning Perl").
    I also read a little about 'system() & exec().

    This is my first actual 'useful' Perl script!!
    I had written this as a Bash script then converted it to Perl.

    --code--

    #!/usr/bin/perl

    use 5.010;
    apart from the (pretty useles say()) there is nothing 5.10 specific
    in the code. I do think say() is not something I would want to make
    my scripts incompatible with older perls for.
    use strict;
    use warnings;

    my ($A, @B, @C, $D);
    Do use meaningful variable names! And declare them together with the
    definition, not upfront.
    $A = 'http://abc.com/texts/files/getthisfile_';

    # For files that are numbered by 01.txt
    # Also can append a '0' to $A & still use @C
    @B = qw { 01 02 03 04 05 06 07 08 09 10 };
    Have a look at spritf().
    $ perldoc -f spritf
    No documentation for perl function `spritf' found

    ;-(
    Silly typos.

    perldoc -f sprintf

    Jenda
    ===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
    When it comes to wine, women and song, wizards are allowed
    to get drunk and croon as much as they like.
    -- Terry Pratchett in Sourcery
  • John Refior at Jun 11, 2009 at 4:03 pm

    On Thu, Jun 11, 2009 at 12:10 AM, raphael() wrote:

    Is there a better way to write this without modules?
    OR is it just too simple & just fine written this way?
    So if I understand correctly, you're trying to get files named like
    getthisfile01.txt through getthisfile10.txt, is that right? If so:

    Here's one way to do it:

    #!/usr/bin/perl

    use strict;use warnings;
    foreach my $num (1..10) { $num =~ s/^([1-9])$/0$1/;
    system('wget', "http://abc.com/texts/files/getthisfile_$num.txt");}

    Here's another:

    #!/usr/bin/perl

    use strict;use warnings;
    foreach my $num (qw(01 02 03 04 05 06 07 08 09 10)) {
    system('wget', "http://abc.com/texts/files/getthisfile_$num.txt");}

    And here's another:

    #!/usr/bin/perl

    use strict;use warnings;
    foreach my $num (1..10) { system('wget',
    'http://abc.com/texts/files/getthisfile_' . sprintf("%02d", $num)) .
    '.txt';}

    John

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJun 11, '09 at 4:10a
activeJun 11, '09 at 7:31p
posts5
users4
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase