Find the answer to your Linux question:
Results 1 to 4 of 4
Hello dear linux-experts i have some consitency-errors within the perl - see below Code: install_cpan_pre.pl #!/usr/bin/perl use strict; use warnings; use Net::FTP; use constant HOST => 'ftp.cpan.org'; use constant DIR1 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    May 2013
    Posts
    258

    i have some consitency-errors within the perl -


    Hello dear linux-experts

    i have some consitency-errors within the perl - see below

    Code:
    install_cpan_pre.pl
    
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use Net::FTP;
    
    use constant HOST  => 'ftp.cpan.org';
    use constant DIR1  => '/pub/CPAN/authors';
    use constant FILE1 => '01mailrc.txt.gz';
    use constant DIR2  => '/pub/CPAN/modules';
    use constant FILE2 => '02packages.details.txt.gz';
    use constant FILE3 => '03modlist.data.gz';
    
    my $ftp = Net::FTP->new(
        HOST, 
        Debug => 0, 
        Passive => 1, 
        Timeout => 1
    );
    
    $ftp->login('anonymous');
    $ftp->cwd(DIR1);
    $ftp->ascii;
    $ftp->get(FILE1);
    $ftp->cwd(DIR2);
    $ftp->get(FILE2);
    $ftp->size(FILE2);
    $ftp->get(FILE3);
    $ftp->quit;
    }
    See how i go on - and what is happening

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use YAML;
    use YAML::Dumper;
    use Parse::CPAN::Authors;
    
    my $list = '/root/01mailrc.txt.gz';
    
    my $p = Parse::CPAN::Authors->new( $list );
    my @authors = $p->authors;
    
    my $dumper = YAML::Dumper->new;
    $dumper->indent_width(1);
    print $dumper->dump({dump => $p}

    some bad things happen


    Code:
    martin@linux-70ce:~/perl> perl cpan2.pl
    Failed to read /root/01mailrc.txt.gz: no permission at /usr/lib/perl5/site_perl/5.18.1/Parse/CPAN/Authors.pm line 22.
    martin@linux-70ce:~/perl>
    guess that i have to put the file into another path

    this one here: /root/01mailrc.txt.gz:

    what do you say?`
    Last edited by sayhello; 06-12-2014 at 08:50 PM.
    Akoya P 6512 15" OpenSuse 13.1: AMD Athlon X2 P320
    Samsunng q 210, 12,1" OpenSuse 13.1: Intel® Core™ 2 Duo Proz. P8400 2,26 GHz 1066 MHz FSB 3 MB

  2. #2
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,656
    I think you're getting ahead of yourself. If you want to learn perl in a unix environment you should learn some of the basics.

    If you ran the first script as root, from /root it would have done the download there but this isn't something you should be doing.

    Perl may be unzipping the the file to disk to read it so unless you're running as root it won't be able to. Another explanation could be that the file is write protected for users other then root.

    Work in your own directory as a normal user for all of your programming exercises - you will avoid a world of hurt this way.

  3. #3
    Linux User
    Join Date
    May 2013
    Posts
    258
    helllo dear gregm

    many thanks - i will do as adviced. i will refine the code .... and run it again....

    install_cpan_pre.pl
    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use Net::FTP;
    
    use constant HOST  => 'ftp.cpan.org';
    use constant DIR1  => '/pub/CPAN/authors';
    use constant FILE1 => '01mailrc.txt.gz';
    use constant DIR2  => '/pub/CPAN/modules';
    use constant FILE2 => '02packages.details.txt.gz';
    use constant FILE3 => '03modlist.data.gz';
    
    my $ftp = Net::FTP->new(
        HOST, 
        Debug => 0, 
        Passive => 1, 
        Timeout => 1
    );
    
    $ftp->login('anonymous');
    $ftp->cwd(DIR1);
    $ftp->ascii;
    $ftp->get(FILE1);
    $ftp->cwd(DIR2);
    $ftp->get(FILE2);
    $ftp->size(FILE2);
    $ftp->get(FILE3);
    $ftp->quit;
    }
    Akoya P 6512 15" OpenSuse 13.1: AMD Athlon X2 P320
    Samsunng q 210, 12,1" OpenSuse 13.1: Intel® Core™ 2 Duo Proz. P8400 2,26 GHz 1066 MHz FSB 3 MB

  4. $spacer_open
    $spacer_close
  5. #4
    Linux User
    Join Date
    May 2013
    Posts
    258
    welll to recap all the story we have a script - that looks like this
    (and it is called cpan2.perl )

    - we see the issue - with the my $list ---/root/

    well this is obviousliy wrong!

    [CODE]
    #!/usr/bin/perl

    use strict;
    use warnings;
    use YAML;
    use YAML:umper;
    use Parse::CPAN::Authors;

    my $list = '/root/01mailrc.txt.gz';

    my $p = Parse::CPAN::Authors->new( $list );
    my @authors = $p->authors;

    my $dumper = YAML:umper->new;
    $dumper->indent_width(1);
    print $dumper->dump({dump => $p}

    [CODE]



    Code:
      martin@linux-70ce:~/perl> perl cpan2.pl Failed to read /root/01mailrc.txt.gz: no permission at
      /usr/lib/perl5/site_perl/5.18.1/Parse/CPAN/Authors.pm line 22. martin@linux-70ce:~/perl>
    guess that i have to put the file into another path this one here:

    Code:
    /root/01mailrc.txt.gz:
    Well, isn't it obvious? I apparently downloaded it as root and are trying to access it as user. chmod or chown should help.

    Well this wont work. Obviously.

    Or we can just try to download it again as user. And a different path would not hurt either, yes.

    But we would have to change it in in the code of cpan2.pl as well.
    Well - Why not just use the current directory there?

    this means we can do it like so:
    i.e.
    Code:
     my $list = '01mailrc.txt.gz'
    by the way: to the the results stored we can do it something a bit like so:

    Code:
     use strict;
    use warnings;
    use DBI;
    
    my $DB = DBI::connect("connect string for your database", "user ID", "password");
    
    # Prepare a statement handle for your inserts
    my $STH = $DB->prepare("insert into mytable (col1, col2) values (?, ?)");
    
    while (<DATA>) {
        # Get  your data
        my ($col1, $col2) = parse_line($_);
        # Now insert it into the database
        $STH->execute($col1, $col2);
    }
    i work on the code -and put the file '01mailrc.txt.gz' into the same directory as the script cpan2 itself is.

    i will work out all and come back and report my findings.
    Akoya P 6512 15" OpenSuse 13.1: AMD Athlon X2 P320
    Samsunng q 210, 12,1" OpenSuse 13.1: Intel® Core™ 2 Duo Proz. P8400 2,26 GHz 1066 MHz FSB 3 MB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •