Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Perl script error

by golux (Chaplain)
on Apr 22, 2016 at 04:58 UTC ( [id://1161182]=note: print w/replies, xml ) Need Help??


in reply to Perl script error

Hi sellinios,

As talexb said, you really need to show some code for us to see where you're having problems.

That said, it's a fair bet the first error you've got:

rm: cannot remove ‘/home/meteo/Build_WRF/DATA/WRF/greece-9km/201604211 +2/wps/FILE:*’: No such file or directory

happened because the code was trying to remove all files a bunch of files that didn't exist. You're probably running on Linux because of the /home dir, and the "rm" command. On my Linux system, the same error (and the same exit status, 256) happen with this test script:

#!/usr/bin/perl -w use strict; use warnings; system("rm dir/FILE:*"); my $err = $?; print "Error is $err\n"; # Output is: rm: cannot remove ‘dir/FILE:*’: No such file or directory Error is 256

If I change that script to use glob and unlink (better because they're Perl builtin functions, hence don't rely on calling the shell which is a more expensive operation):

#!/usr/bin/perl -w use strict; use warnings; foreach my $file (glob("dir/FILE:*")) { if (!unlink($file)) { print "Warning: failed to remove file '$file' ($!)\n"; } }

That way, if there aren't any files, it won't fail due to shell not finding any matches.

It's interesting to note that the shell will always do its own globbing before passing results to the command (rm in your case) -- to verify this, you can try "echo *" and see all your files/dirs the way they'd look prior to passing them to any Unix command ("ls" for example).

And unlike Perl, the shell will throw an error if a wildcard such as "*" or "?" fails to find any matching files.

say  substr+lc crypt(qw $i3 SI$),4,5

Replies are listed 'Best First'.
Re^2: Perl script error
by sellinios (Initiate) on Apr 22, 2016 at 09:49 UTC
    I have gave you a link with my git. Did you see that?

      Thanks for your reply -- and welcome to The Monastery.

      Here's the way this site works: people post questions about Perl on the site, and other people answer them.

      Sometimes the questions spark an interesting discussion about computer science, algorithms, operating systems -- it can be quite fascinating. Sometimes people are directed to the excellent documentation that's already available (I've even contributed to the docs myself -- it's awesome to see your own name in Perl's credits).

      And sometimes people have a question about their code. When the code isn't provided directly, it's a bit of a thought experiment to figure out what might be wrong. The whole thing's a black box. This can be entertaining, but it's most likely unsatisfying for the developer trying to solve their problem. So we encourage the posting of the code in question directly on this site, rather than provided by a link off-site.

      Why? Because sometimes the discussion we have today can be useful in a year's time. And in a year, the file that you've put on bitbucket.org (or whatever) could be gone, leaving a bit of a hole in the discussion.

      In addition, if you can pare down your example to the barest of necessities to show the problem (and, of course, use strict and use warnings), that will make it easy for us to diagnose the problem and provide a solution.

      And this is a somewhat long-winded post, but I'm attempting to forestall the inevitable back-and-forth that happens when a new member arrives.

      Post something useful, read, learn, listen, become a better developer. And (this is my favorite Larry Wall quote), ".. have the appropriate amount of fun."

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

        Ok I got your point, so bellow is the file I think it has the issue :
        #!/usr/bin/perl -w use Class::Date qw(date now); use File::Path; use File::Copy; use List::Util qw(min max); chomp( $region = $ARGV[0] ); chomp( $lrun = $ARGV[1] ); chomp( $flag = $ARGV[2] ); if ( $flag =~ m/^(00|06|12|18)$/ ) { $hh = $flag; chomp( $yyyymmdd = `date +%Y%m%d` ); $yymmdd = substr( $yyyymmdd, 2, 6 ); $real_time = 1; } elsif ( $flag =~ m!^(19|20)\d\d(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])(00|06|12|18) +$! ) { $yyyymmdd = substr( $flag, 0, 8 ); $yymmdd = substr( $yyyymmdd, 2, 6 ); $hh = substr( $flag, 8, 2 ); $real_time = 1; } $yyyymmddhh = $yyyymmdd . $hh; $Class::Date::DATE_FORMAT = "%Y-%m-%d_%H:%M:%S"; $data_inici = date $yyyymmddhh. "0000"; $copyright = $data_inici->year; $data_final = $data_inici + "$lrun h"; $root = '/home/meteo/Build_WRF'; $regdir = "$root/SCRIPTS$region"; $wpsdir = "$root/WPS"; $wrfdir = "$root/WRFV3"; $wrfdmdir = "$root/WRFV3"; $postdir = "$root/ARWpost"; $rundir = "$root/DATA/WRF/$region/$yyyymmddhh"; $gfsdir = '/home/meteo/Build_WRF/DATA/GFS'; $mapsdir = "/home/meteo/Build_WRF/DATA/MAPS/$region/$ +yyyymmddhh"; $grads = '/home/meteo/Build_WRF/LIBRARIES/grads/bin/grads'; if ( !-d $mapsdir ) { mkpath($mapsdir) or die $!; } else { rmtree($mapsdir) or die $!; mkpath($mapsdir) or die $!; } chdir("$rundir/arwpost") or die $!; %var_list = ( 'prec' => 'Total precipitation (mm)', 't2m' => 'Temperature at 2m (Celsius)', 't850' => 'Temperature at 850hPa (Celsius)', 't500' => 'Temperature at 500hPa (Celsius)', 't700' => 'Temperature at 700hPa (Celsius)', 'slp' => 'Sea level pressure (hPa)', 'clfr' => 'Total cloud clover (%)', 'prec_slp' => 'Precipitation (mm) and SLP (hPa)', 'prec_type' => 'Precipitation type', 'frozen_lvl' => 'Frozen level (m)', 'wind10_slp' => 'Wind 10m (m/s) and SLP (hPa)', 'prec24' => '24h Precipitation (mm)', 'acsnow' => 'Accumulated snow and ice (mm) + snow cover', # 'cape' => 'CAPE (J/kg)' ); @doms = ( 'd01', 'd02' ); foreach (@doms) { $domain = $_; if ( $domain eq 'd01' ) { $xsize = '850'; $ysize = '650'; $img_size = '850x650'; $latmin = '34.0'; $latmax = '72.5'; $lonmin = '-12.3333'; $lonmax = '39.0'; $logo_size = '+130+540'; $region_plot = 'europe-27km'; $gradsdir = "$root/Build_WRF/SCRIPTS/grads_europe"; } elsif ( $domain eq 'd02' ) { $xsize = '850'; $ysize = '650'; $img_size = '850x650'; $latmin = '34.6875'; $latmax = '41.8125'; $lonmin = '19.0'; $lonmax = '28.5'; $logo_size = '+130+540'; $region_plot = 'greece-9km'; $gradsdir = "$root/Build_WRF/SCRIPTS/grads_greece"; } elsif ( $domain eq 'd03' ) { $xsize = '850'; $ysize = '650'; $img_size = '850x650'; $latmin = '37.3875'; $latmax = '39.1125'; $lonmin = '23.0'; $lonmax = '25.3'; $logo_size = '+130+540'; $region_plot = 'attica-3km'; $gradsdir = "$root/Build_WRF/SCRIPTS/grads_attica"; } $mapsdir = "/home/meteo/Build_WRF/DATA/MAPS/$region_plot/$yyyymmdd +hh"; if ( !-d $mapsdir ) { mkpath($mapsdir) or die $!; } else { rmtree($mapsdir) or die $!; mkpath($mapsdir) or die $!; } chdir("$rundir/arwpost") or die $!; while ( ( $var, $name ) = each(%var_list) ) { print("$var, $fname\n"); if ( $var eq 'prec' || $var eq 'prec_type' || $var eq 'prec_sl +p' ) { $data = $data_inici; while ( $data <= $data_final ) { print "$region_plot $gradsdir $var \"$name\" $data\n"; $Class::Date::DATE_FORMAT = "%Y-%m-%d %H"; $title = "$name $data UTC"; $Class::Date::DATE_FORMAT = "%Y%m%d%H"; $pngfile = "$data\_$var.png"; $Class::Date::DATE_FORMAT = "%Y-%m-%d_%H:%M:%S"; $ctlfile = "wrfout_$domain\_$data.ctl +"; $data2 = $data - '1h'; $ctlfile2 = "wrfout_$domain\_$data2.ct +l"; if ( $data != $data_inici ) { open( GS1, ">$rundir/arwpost/commands.gs" ) or die + $!; print GS1 "'open $ctlfile'\n"; print GS1 "'open $ctlfile2'\n"; print GS1 "'clear'\n"; print GS1 "'set lat $latmin $latmax'\n"; print GS1 "'set lon $lonmin $lonmax'\n"; print GS1 "'run $gradsdir/$var\_in.gs'\n"; print GS1 "'run $gradsdir/xcbar.gs -fs 3 -edge cir +cle'\n"; print GS1 "'set font 0'\n"; print GS1 "'set rgb 100 100 0 100'\n"; print GS1 "'set map 1 1 6'\n"; print GS1 "'set string 1 tc 5'\n"; print GS1 "'draw string 5.5 0.4 kairos.gr copyrigh +t $copyright'\n"; print GS1 "'set strsiz 0.18'\n"; print GS1 "'set string 1 tc 9'\n"; print GS1 "'draw string 5.5 8.2 $title'\n"; print GS1 "'set mpdraw off'\n"; print GS1 "'printim $mapsdir/$pngfile png white x$ +xsize y$ysize -b /home/meteo/Build_WRF/SCRIPTS/background.png'\n"; print GS1 "'quit'\n"; close(GS1); } else { open( GS2, ">$rundir/arwpost/commands.gs" ) or die + $!; print GS2 "'open $ctlfile'\n"; print GS2 "'clear'\n"; print GS2 "'set lat $latmin $latmax'\n"; print GS2 "'set lon $lonmin $lonmax'\n"; print GS2 "'run $gradsdir/$var.gs'\n"; print GS2 "'run $gradsdir/xcbar.gs -fs 3 -edge cir +cle'\n"; print GS2 "'set font 0'\n"; print GS2 "'set rgb 100 100 0 100'\n"; print GS2 "'set map 1 1 6'\n"; print GS2 "'set string 1 tc 5'\n"; print GS2 "'draw string 5.5 0.4 kairos.gr copyrigh +t $copyright'\n"; print GS2 "'set strsiz 0.18'\n"; print GS2 "'set string 1 tc 9'\n"; print GS2 "'draw string 5.5 8.2 $title'\n"; print GS2 "'set mpdraw off'\n"; print GS2 "'printim $mapsdir/$pngfile png white x$ +xsize y$ysize'\n"; print GS2 "'quit'\n"; close(GS2); } @args = ("$grads -blc $rundir/arwpost/commands.gs > /d +ev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; open( LG, ">$rundir/arwpost/composite.sh" ) or die $!; print LG "#!/bin/bash\n"; print LG "convert -size $img_size xc:white $mapsdir/co +mposite.png\n"; print LG "composite -geometry +0+0 $mapsdir/$pngfile $ +mapsdir/composite.png $mapsdir/composite.png\n"; print LG "mv $mapsdir/composite.png $mapsdir/$pngfile" +; close(LG); my $file = "$rundir/arwpost/composite.sh"; chmod 0755, $file or die "Couldn't chmod $file: $!"; @args = ("$file > /dev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; $data = $data + '1h'; } } elsif ($var eq 't2m' || $var eq 't850' || $var eq 't500' || $v +ar eq 'slp' || $var eq 'clfr' || $var eq 'frozen_lvl' || $var eq 'wind1 +0_slp' || $var eq 'acsnow' || $var eq 'cape' ) { $data = $data_inici; while ( $data <= $data_final ) { print "$region_plot $gradsdir $var \"$name\" $data\n"; $Class::Date::DATE_FORMAT = "%Y-%m-%d %H"; $title = "$name $data UTC"; $Class::Date::DATE_FORMAT = "%Y%m%d%H"; $pngfile = "$data\_$var.png"; $Class::Date::DATE_FORMAT = "%Y-%m-%d_%H:%M:%S"; $ctlfile = "wrfout_$domain\_$data.ctl +"; open( GS3, ">$rundir/arwpost/commands.gs" ) or die $!; print GS3 "'open $ctlfile'\n"; print GS3 "'clear'\n"; print GS3 "'set lat $latmin $latmax'\n"; print GS3 "'set lon $lonmin $lonmax'\n"; print GS3 "'run $gradsdir/$var.gs'\n"; print GS3 "'run $gradsdir/xcbar.gs -fs 3 -edge circle' +\n"; print GS3 "'set font 0'\n"; print GS3 "'set rgb 100 100 0 100'\n"; print GS3 "'set map 1 1 6'\n"; print GS3 "'set string 1 tc 5'\n"; print GS3 "'draw string 5.5 0.4 kairos.gr copyright $c +opyright'\n"; print GS3 "'set strsiz 0.18'\n"; print GS3 "'set string 1 tc 9'\n"; print GS3 "'draw string 5.5 8.2 $title'\n"; print GS3 "'set mpdraw off'\n"; print GS3 "'printim $mapsdir/$pngfile png white x$xsiz +e y$ysize'\n"; print GS3 "'quit'\n"; close(GS3); @args = ("$grads -blc $rundir/arwpost/commands.gs > /d +ev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; open( LG, ">$rundir/arwpost/composite.sh" ) or die $!; print LG "#!/bin/bash\n"; print LG "convert -size $img_size xc:white $mapsdir/co +mposite.png\n"; print LG "composite -geometry +0+0 $mapsdir/$pngfile $ +mapsdir/composite.png $mapsdir/composite.png\n"; print LG "mv $mapsdir/composite.png $mapsdir/$pngfile" +; close(LG); my $file = "$rundir/arwpost/composite.sh"; chmod 0755, $file or die "Couldn't chmod $file: $!"; @args = ("$file > /dev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; $data = $data + '1h'; } } elsif ( $var eq 'prec24' ) { $data = $data_inici; while ( $data < $data_final ) { print "$region_plot $gradsdir $var \"$name\" $data\n"; $Class::Date::DATE_FORMAT = "%Y-%m-%d %H"; $title = "$name $data UTC"; $Class::Date::DATE_FORMAT = "%Y%m%d%H"; $pngfile = "$data\_$var.png"; $data = $data + '24h'; $Class::Date::DATE_FORMAT = "%Y-%m-%d_%H:%M:%S"; $ctlfile = "wrfout_$domain\_$data.ctl +"; $data2 = $data - '24h'; $ctlfile2 = "wrfout_$domain\_$data2.ct +l"; open( GS4, ">$rundir/arwpost/commands.gs" ) or die $!; print GS4 "'open $ctlfile'\n"; print GS4 "'open $ctlfile2'\n"; print GS4 "'clear'\n"; print GS4 "'set lat $latmin $latmax'\n"; print GS4 "'set lon $lonmin $lonmax'\n"; print GS4 "'run $gradsdir/$var\_in.gs'\n"; print GS4 "'run $gradsdir/xcbar.gs -fs 3 -edge circle' +\n"; print GS4 "'set font 0'\n"; print GS4 "'set rgb 100 100 0 100'\n"; print GS4 "'set map 1 1 6'\n"; print GS4 "'set strsiz 0.18'\n"; print GS4 "'set string 1 tc 5'\n"; print GS4 "'draw string 5.5 0.4 kairos.gr copyright $c +opyright'\n"; print GS4 "'set string 1 tc 9'\n"; print GS4 "'draw string 5.5 8.2 $title'\n"; print GS4 "'set mpdraw off'\n"; print GS4 "'printim $mapsdir/$pngfile png white x$xsiz +e y$ysize -b /home/meteo/Build_WRF/SCRIPTS/background.png'\n"; print GS4 "'quit'\n"; close(GS4); @args = ("$grads -blc $rundir/arwpost/commands.gs > /d +ev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; open( LG, ">$rundir/arwpost/composite.sh" ) or die $!; print LG "#!/bin/bash\n"; print LG "convert -size $img_size xc:white $mapsdir/co +mposite.png\n"; print LG "composite -geometry +0+0 $mapsdir/$pngfile $ +mapsdir/composite.png $mapsdir/composite.png\n"; print LG "mv $mapsdir/composite.png $mapsdir/$pngfile" +; close(LG); my $file = "$rundir/arwpost/composite.sh"; chmod 0755, $file or die "Couldn't chmod $file: $!"; @args = ("$file > /dev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; } } } } exit;
Re^2: Perl script error
by sellinios (Initiate) on Apr 22, 2016 at 11:08 UTC
    https://bitbucket.org/lefteris_papadopoulos/meteo/src

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1161182]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-23 21:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found