Please help with some very simple code below which somehow I a, not getting 
right.
I have strings consisting of $day, $month, $year, $hour, $min, followed by some 
float values which I call @rain, as in the attached file 'text1.txt'.
I want rewrite this data as $year, $month, $day, $hour, $min,  @rainin as in  
'text2.txt', but with the date also formatted to have one space between each 
field
Help will be appreciated.
Zilore


#!/usr/bin/perl -w
use strict;                                                                     
           
use warnings;

  open (IN, "< text1") or die "open 'text1' failed: $!\n";
  open (OUT, ">$text2") or die "open 'text1' failed: $!\n";

  # Copy first 3 lines unchanged.
  print OUT scalar(<IN>) for 1..3;

  # Reformat the numbers on each remaining line.

  while (<IN>)
  {
   my ($month,$day,$year,$hour,$min,@rain) = split;
   
 # printf ("%04d%02d%02d%02d%02d\n",$year,$month,$day,$hour,$min);
   $_ = sprintf "%5.1f", $_ foreach @rain;
  
   print OUT ($year,$month,$day,$hour,$min, join(" ", @rain), "\n");
  }

  # Close files
  close IN or die "close IN: $!\n";
  close OUT or die "close OUT failed: $!\n";
 }
1 1 2012 12 00 00   < > 1 10 2012 9 00 00                                       
                                                                                
                                                                                
                        
                                                                                
                                                                                
                                                                        
          Date Time     Humidity Min (%)        Humidity Ave (%)        
Humidity Max (%)        Humidity StDev (%)      Temperatur Min ('C)     
Temperatur Ave ('C)     Temperatur Max ('C)     Temperatur StDev ('C)   
ATMPressure Min (hPa)   ATMPressure Ave (hPa)   ATMPressure Max (hPa)   
ATMPressure StDev (hPa) Glob.Rad. Min (W m2)    Glob.Rad. Ave (W m2)    
Glob.Rad. Max (W m2)    Glob.Rad. StDev (W m2)  RAIN Tot (mm)   POWER Inst (V)  
Int.Temp. Inst ('C)     WindSPEED Min (m s)     WindSPEED Ave (m s)     
WindSPEED Max (m s)     WindSPEED StDev (m s)   WindDIR PrevDir (>)     WindDIR 
RisDir (>)      WindDIR RisVel (>)      WindDIR StdDevDir (>)   WindDIR 
CalmPerc (>)
          1 1 2012 12 00        96.5    98.2    99.8    1.4     13.3    13.46   
13.56   0.1     849.2   849.2   849.3   0       0       0       0       0       
0       12.6    14.11   0.94    2.49    4.84    0.7     50      51      2       
14      0
          1 1 2012 12 10        99      99.2    99.5    0.2     13.31   13.36   
13.38   0.02    849.2   849.2   849.3   0       0       0       0       0       
0       12.7    14.13   0.7     2.04    3.42    0.45    50      50      2       
12      0
          1 1 2012 12 20        97.3    98.4    99.5    0.9     13.29   13.41   
13.53   0.11    849.2   849.2   849.3   0       0       0       0       0       
0       12.7    14.1    0.76    2.24    3.44    0.56    43      42      2       
10      0
          1 1 2012 12 30        97.8    98.9    100     0.8     13.27   13.38   
13.49   0.07    849.2   849.2   849.3   0       0       0       0       0       
0       12.7    14.1    0.36    1.23    1.98    0.4     35      36      1       
9       0
          1 1 2012 12 40        98.9    99.7    100     0.4     13.06   13.17   
13.25   0.07    849.2   849.2   849.2   0       0       0       0       0       
0       12.7    14.09   0.45    1.46    2.88    0.43    38      39      1       
12      0
          1 1 2012 12 50        98.1    99.7    100     0.6     13.09   13.14   
13.19   0.04    849.1   849.2   849.2   0.3     0       0       0       0       
0       12.7    14.03   0       0.63    1.73    0.41    58      51      0       
78      30
          1 1 2012 1 00         94.5    95.5    97.4    1       12.92   13.06   
13.16   0.09    849.2   849.2   849.2   0.3     0       0       0       0       
0       12.7    14.03   0.06    0.66    1.22    0.26    302     310     1       
37      10
          1 1 2012 1 10         94.6    95.6    96.5    0.7     12.9    12.96   
13.04   0.05    849.1   849.2   849.2   0.3     0       0       0       0       
0       12.7    13.97   0.34    1.01    1.72    0.25    314     316     1       
16      0
          1 1 2012 1 20         93.7    94.6    95.6    0.7     12.91   13.01   
13.05   0.04    849.1   849.2   849.2   0       0       0       0       0       
0       12.7    13.93   0.11    0.66    1.55    0.22    288     290     1       
26      5
          1 1 2012 1 30         91.6    92.5    93.6    0.7     12.89   12.96   
13      0.04    849.1   849.2   849.2   0       0       0       0       0       
0       12.7    13.89   0.36    0.93    1.49    0.21    293     293     1       
16      0
          1 1 2012 1 40         91.7    92.4    93.7    0.7     12.74   12.77   
12.83   0.03    849.1   849.1   849.1   0       0       0       0       0       
0       12.7    13.86   0.48    0.95    1.49    0.21    313     314     1       
12      0
          1 1 2012 1 50         94.1    95.7    97      1       12.79   12.83   
12.86   0.03    849.1   849.1   849.2   0       0       0       0       0       
0       12.7    13.83   0.78    1.25    1.85    0.21    325     325     1       
8       0
          1 1 2012 2 00         97.3    98.7    99.5    0.8     12.87   12.92   
12.96   0.03    849.1   849.2   849.2   0       0       0       0       0       
0       12.7    13.79   0.53    1.11    1.67    0.23    350     349     1       
12      0
          1 1 2012 2 10         99.1    99.7    100     0.3     12.89   12.96   
13.03   0.05    849.2   849.2   849.2   0.3     0       0       0       0       
0       12.7    13.75   0.38    0.89    1.32    0.19    310     311     1       
14      0
          1 1 2012 2 20         97.8    98.2    98.9    0.4     13.04   13.12   
13.16   0.04    849.2   849.2   849.2   0       0       0       0       0       
0       12.7    13.67   0.69    1.18    1.75    0.2     342     342     1       
12      0
          1 1 2012 2 30         97.9    98.9    99.5    0.6     13      13.08   
13.15   0.06    849.2   849.2   849.2   0       0       0       0       0       
0       12.7    13.64   0.51    1.03    1.74    0.24    21      18      1       
18      0
          1 1 2012 2 40         98      98.7    99.2    0.5     13.03   13.06   
13.11   0.02    849.2   849.2   849.2   0.3     0       0       0       0       
0       12.7    13.6    0.53    1.41    2.41    0.4     1       359     1       
16      0
          1 1 2012 2 50         97.9    98.4    98.6    0.2     13.03   13.06   
13.1    0.02    849.2   849.2   849.2   0       0       0       0       0       
0       12.7    13.59   0.56    1.04    2.07    0.32    17      15      1       
11      0
          1 1 2012 3 00         98.7    99.1    99.4    0.2     12.97   13      
13.03   0.02    849.2   849.2   849.2   0.4     0       0       0       0       
0       12.7    13.57   0.77    1.08    1.47    0.15    19      19      1       
8       0
          1 1 2012 3 10         95.7    97.9    99.3    1.4     12.94   13.01   
13.15   0.07    849.2   849.2   849.2   0.3     0       0       0       0       
0       12.7    13.54   0.42    1.1     1.87    0.41    357     355     1       
13      0
          1 1 2012 3 20         95      95.5    96.1    0.4     13.08   13.14   
13.18   0.04    849.2   849.2   849.2   0.3     0       0       0       0       
0       12.7    13.51   0.48    1.14    1.76    0.27    6       5       1       
12      0
          1 1 2012 3 30         93.4    95.5    96.8    1.3     13.07   13.12   
13.23   0.06    849.2   849.2   849.2   0.3     0       0       0       0       
0       12.7    13.48   0.35    0.68    1.53    0.18    16      15      1       
11      0
          1 1 2012 3 40         89.9    91      91.8    0.5     13.25   13.34   
13.42   0.05    849.2   849.2   849.2   0       0       0       0       0       
0       12.7    13.45   0.08    0.53    0.88    0.16    288     283     0       
49      10
1 1 2012 12 00 00   < > 1 10 2012 9 00 00                                       
                                                                                
                                                                                
                        
                                                                                
                                                                                
                                                                        
          Date Time     Humidity Min (%)        Humidity Ave (%)        
Humidity Max (%)        Humidity StDev (%)      Temperatur Min ('C)     
Temperatur Ave ('C)     Temperatur Max ('C)     Temperatur StDev ('C)   
ATMPressure Min (hPa)   ATMPressure Ave (hPa)   ATMPressure Max (hPa)   
ATMPressure StDev (hPa) Glob.Rad. Min (W m2)    Glob.Rad. Ave (W m2)    
Glob.Rad. Max (W m2)    Glob.Rad. StDev (W m2)  RAIN Tot (mm)   POWER Inst (V)  
Int.Temp. Inst ('C)     WindSPEED Min (m s)     WindSPEED Ave (m s)     
WindSPEED Max (m s)     WindSPEED StDev (m s)   WindDIR PrevDir (>)     WindDIR 
RisDir (>)      WindDIR RisVel (>)      WindDIR StdDevDir (>)   WindDIR 
CalmPerc (>)
2012111200 96.5  98.2  99.8   1.4  13.3  13.5  13.6   0.1 849.2 849.2 849.3   
0.0   0.0   0.0   0.0   0.0   0.0  12.6  14.1   0.9   2.5   4.8   0.7  50.0  
51.0   2.0  14.0   0.0
2012111210 99.0  99.2  99.5   0.2  13.3  13.4  13.4   0.0 849.2 849.2 849.3   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  14.1   0.7   2.0   3.4   0.5  50.0  
50.0   2.0  12.0   0.0
2012111220 97.3  98.4  99.5   0.9  13.3  13.4  13.5   0.1 849.2 849.2 849.3   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  14.1   0.8   2.2   3.4   0.6  43.0  
42.0   2.0  10.0   0.0
2012111230 97.8  98.9 100.0   0.8  13.3  13.4  13.5   0.1 849.2 849.2 849.3   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  14.1   0.4   1.2   2.0   0.4  35.0  
36.0   1.0   9.0   0.0
2012111240 98.9  99.7 100.0   0.4  13.1  13.2  13.2   0.1 849.2 849.2 849.2   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  14.1   0.5   1.5   2.9   0.4  38.0  
39.0   1.0  12.0   0.0
2012111250 98.1  99.7 100.0   0.6  13.1  13.1  13.2   0.0 849.1 849.2 849.2   
0.3   0.0   0.0   0.0   0.0   0.0  12.7  14.0   0.0   0.6   1.7   0.4  58.0  
51.0   0.0  78.0  30.0
201211100 94.5  95.5  97.4   1.0  12.9  13.1  13.2   0.1 849.2 849.2 849.2   
0.3   0.0   0.0   0.0   0.0   0.0  12.7  14.0   0.1   0.7   1.2   0.3 302.0 
310.0   1.0  37.0  10.0
201211110 94.6  95.6  96.5   0.7  12.9  13.0  13.0   0.1 849.1 849.2 849.2   
0.3   0.0   0.0   0.0   0.0   0.0  12.7  14.0   0.3   1.0   1.7   0.2 314.0 
316.0   1.0  16.0   0.0
201211120 93.7  94.6  95.6   0.7  12.9  13.0  13.1   0.0 849.1 849.2 849.2   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  13.9   0.1   0.7   1.6   0.2 288.0 
290.0   1.0  26.0   5.0
201211130 91.6  92.5  93.6   0.7  12.9  13.0  13.0   0.0 849.1 849.2 849.2   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  13.9   0.4   0.9   1.5   0.2 293.0 
293.0   1.0  16.0   0.0
201211140 91.7  92.4  93.7   0.7  12.7  12.8  12.8   0.0 849.1 849.1 849.1   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  13.9   0.5   0.9   1.5   0.2 313.0 
314.0   1.0  12.0   0.0
201211150 94.1  95.7  97.0   1.0  12.8  12.8  12.9   0.0 849.1 849.1 849.2   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  13.8   0.8   1.2   1.9   0.2 325.0 
325.0   1.0   8.0   0.0
201211200 97.3  98.7  99.5   0.8  12.9  12.9  13.0   0.0 849.1 849.2 849.2   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  13.8   0.5   1.1   1.7   0.2 350.0 
349.0   1.0  12.0   0.0
201211210 99.1  99.7 100.0   0.3  12.9  13.0  13.0   0.1 849.2 849.2 849.2   
0.3   0.0   0.0   0.0   0.0   0.0  12.7  13.8   0.4   0.9   1.3   0.2 310.0 
311.0   1.0  14.0   0.0
201211220 97.8  98.2  98.9   0.4  13.0  13.1  13.2   0.0 849.2 849.2 849.2   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  13.7   0.7   1.2   1.8   0.2 342.0 
342.0   1.0  12.0   0.0
201211230 97.9  98.9  99.5   0.6  13.0  13.1  13.2   0.1 849.2 849.2 849.2   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  13.6   0.5   1.0   1.7   0.2  21.0  
18.0   1.0  18.0   0.0
201211240 98.0  98.7  99.2   0.5  13.0  13.1  13.1   0.0 849.2 849.2 849.2   
0.3   0.0   0.0   0.0   0.0   0.0  12.7  13.6   0.5   1.4   2.4   0.4   1.0 
359.0   1.0  16.0   0.0
201211250 97.9  98.4  98.6   0.2  13.0  13.1  13.1   0.0 849.2 849.2 849.2   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  13.6   0.6   1.0   2.1   0.3  17.0  
15.0   1.0  11.0   0.0
201211300 98.7  99.1  99.4   0.2  13.0  13.0  13.0   0.0 849.2 849.2 849.2   
0.4   0.0   0.0   0.0   0.0   0.0  12.7  13.6   0.8   1.1   1.5   0.1  19.0  
19.0   1.0   8.0   0.0
201211310 95.7  97.9  99.3   1.4  12.9  13.0  13.2   0.1 849.2 849.2 849.2   
0.3   0.0   0.0   0.0   0.0   0.0  12.7  13.5   0.4   1.1   1.9   0.4 357.0 
355.0   1.0  13.0   0.0
201211320 95.0  95.5  96.1   0.4  13.1  13.1  13.2   0.0 849.2 849.2 849.2   
0.3   0.0   0.0   0.0   0.0   0.0  12.7  13.5   0.5   1.1   1.8   0.3   6.0   
5.0   1.0  12.0   0.0
201211330 93.4  95.5  96.8   1.3  13.1  13.1  13.2   0.1 849.2 849.2 849.2   
0.3   0.0   0.0   0.0   0.0   0.0  12.7  13.5   0.3   0.7   1.5   0.2  16.0  
15.0   1.0  11.0   0.0
201211340 89.9  91.0  91.8   0.5  13.2  13.3  13.4   0.1 849.2 849.2 849.2   
0.0   0.0   0.0   0.0   0.0   0.0  12.7  13.4   0.1   0.5   0.9   0.2 288.0 
283.0   0.0  49.0  10.0
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to