Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] Re: Help! (what a classic)...concatenation operator on drugz?!?

Expand Messages
  • Eric Thibodeau
    A million thanks, it seems to work fine with the sprinf and also thanks for the unlink tip...never thought unlink was for deleting a file! I guess that, when
    Message 1 of 4 , Mar 30, 2001
    • 0 Attachment
      A million thanks, it seems to work fine with the sprinf and also
      thanks for the unlink tip...never thought unlink was for deleting a file! I
      guess that, when in doubt, do it the "C" way :o).

      Eric Thibodeau

      -----Original Message-----
      From: Damien Carbery [mailto:daymobrew@...]
      Sent: Friday, March 30, 2001 12:57 PM
      To: perl-beginner@yahoogroups.com
      Subject: [PBML] Re: Help! (what a classic)...concatenation operator on
      drugz?!?


      I don't know about your concetenation issues but I noticed one small
      thing:

      > print "\n\nRemoving $Prm\n";
      > @Rslt=split(/ /,`rm $Prm`);
      > if($Debug){
      > print "\`rm\` result: @Rslt\n";}
      > }
      I recommend using perl to remove the file instead of invoking an
      external program (time and CPU intensive, even though this is probably
      not an issue here).
      my $UnlinkResult;
      print "\n\nRemoving $Prm\n";
      $UnlinkResult = unlink( $Prm );
      print "unlink result (1 is good): $UnlinkResult\n" if ( $Debug );

      Maybe you could try using sprintf() to concatenate the "1":
      sprintf( $Prn, "%s%s", $Prn, "1" );
      I realise this is not a nice solution.

      --- In perl-beginner@y..., rd_lab@e... wrote:
      > Hello everyone,
      >
      > I am attempting to write a PERL script to automate the setup
      > of SBC (Single Board Computers). Part of this script initializes the
      > flash RAM (using mknod and sfdisk). Configuration parameters such as
      > the device name (/dev/hrfd) and the Major nummber (for mknod) are
      > stored in a configuration file. Okay..to up to now, this is not too
      > complicated...here is the weird part...and hoping someone has heard
      > of this:
      >
      > - The script must also create the device /dev/hrfd1.
      > Since /dev/hrfd is a variable read from the configuration file,
      > I "simply" concatenate the variable contaning /etc/hrfd with "1".
      For
      > some completely unknown reason, the concatenation screws up
      > completely and adds the "1" at the begining of the variable giving
      > 1dev/hrfd as I print out the resulting variable. Moreover, I also
      > print "Removing $Prm"...and this is the really freaky part, the "1"
      > which should have been concatenated to the $Prm (/dev/hrfd) ends up
      > replacing the first caracter of the printed string
      > rendering "1emonving /dev/hrfd" on the display.
      >
      > - At this point, I am not too certain what information is
      > really relevant to my problem but here are some of the information
      > relevant to the environment:
      >
      > OS: Mandrake 7.1
      > Perl -V: 2.2.15-0.16mdksmp (rpm from mandrake 7.1 CD)...perl
      > version 5.6.0
      > Hardware: Pentium 75, 32MB RAM
      >
      > Note that I have also experienced this problem on the same
      > machine with Mandrake 8.0Beta1.
      >
      > The reason why I regressed to Mandrake 7.1 is that my script
      > runs correctly on my coworker's machine which is runing Mandrake
      7.1.
      > Having formatted and reinstalled Mandrake, I can pretty much
      > eliminate library problems...I think.
      >
      > I have attached the scipt to this e-mail as well as the relevent
      > configuration file. Note that the configuration file must be in a
      > directory named config relative to the script's path.
      >
      > Please bare in mind that I am pretty much inexperienced in
      > Perl am I begg you all to excuse me for the most-probably-mediocre
      > quality of my script
      >
      > Thanks a millon,
      >
      > Eric Thibodeau
      >
      >
      > -=-=-=-=-=-= Start of PERL script (install.pl) -=-=-=-=-=-=
      >
      > #!/usr/bin/perl -W
      > #Date: 2001/03/22
      > #Auteur: Eric Thibodeau
      > #Script d'installation de Linux sur les SBC
      >
      > $Debug = 1;
      >
      > print "\nWelcome - Installation script!\nBienvenue au script
      > d'installation!\n";
      >
      > GetConfigs(); #crée @Configs (string des noms de fichiers) et
      > $ConfNum (nombre de fichiers de config)
      > PrintConfigs(); #Imprime les choix de config valides
      > ChooseConfig(); #crée $Choix; demande au user de choisir la config
      > voulue
      > LoadConfig(); #Parse le fichier de config et load les infos dans %
      > Parms où Paramètres == keys(%Parms) et Valeure == value(%Parms)
      > MakeDisk(); #Crée la partition surle SBC
      >
      > sub GetConfigs{
      > @Configs=glob("./config/*.cfg");
      > $ConfNum=(@Configs)-1;
      > }
      >
      > sub PrintConfigs{
      > my ($i)=0;
      > my ($tmp);
      > print "\nPlease select your installation class\nSVP, choisir
      > votre classe d'installation.\n";
      > while($i<=$ConfNum){
      > print "\n\t$i.";
      > $tmp = $Configs[$i];
      > $tmp =~ s#.*/##; #ici, # est utilisé à la
      > place de / pour rendre la ligne de code plus lisible que "s/.*\///"
      > # $tmp =~ s/.*\///; # autre façon de faire la
      > même chose...
      > print "$tmp";
      > $i++;
      > }
      > print"\n\tm.Manual Mode Manuel";
      > print"\n\n(0-$ConfNum Or/Ou m):";
      > }
      >
      > sub ChooseConfig{
      > my ($Done)=0;
      > while(!$Done){
      > $Choix=<STDIN>;
      > if ($Choix =~ /M/i) {exit;}
      > elsif ($Choix>$ConfNum){PrintConfigs();}
      > else {$Done=1;}
      > }
      > }
      >
      > sub LoadConfig{
      > my (%Tmp, $k, @key);
      > print "\nChosen configuration choisise:$Configs[$Choix]\n";
      > open(CFG,"<$Configs[$Choix]");
      >
      > foreach(<CFG>){
      > if($_ =~ /^\w/){ #pour enlever les
      > commentaires...ignore les
      > #lignes ne commençaint pas alpha-num
      > ou "_"
      > ($Parm,$Value)=split(/\s=\s/);
      > chomp($Value);
      > $Tmp{$Parm}=$Value;
      > %Parms=(%Parms,%Tmp);
      > }
      > }
      > close CFG;
      >
      > print "\n Read configuration / Configuration lue:\n";
      > foreach $k(@key=keys(%Parms)){
      > print "\n\t $k-->$Parms{$k}";}
      > print "\n\n";
      > }
      >
      > sub MakeDisk{
      > print "\n\nCreating partition table - Création de la table
      > des partitions\n\n";
      >
      > KillNodes();
      > #$tmp=<STDIN>; #debug screen pause
      > MakeNodes();
      > #$tmp=<STDIN>; #debug screen pause
      > FormatDsk();
      >
      > }
      >
      > sub KillNodes{
      > my ($Prm);
      > #remove /dev/????
      > $Prm=$Parms{"device"};
      > print "\nRemoving $Prm\n";
      > @Rslt=split(/ /,`rm $Prm`);
      > if($Debug){
      > print "\`rm\` result: @Rslt\n";}
      >
      > #remove /dev/????1
      > $Prm.="1";
      > print $Prm;
      > print "\n\nRemoving $Prm\n";
      > @Rslt=split(/ /,`rm $Prm`);
      > if($Debug){
      > print "\`rm\` result: @Rslt\n";}
      > }
      >
      > sub MakeNodes{
      > my ($tmp);
      > #create /dev/????
      > $tmp=$Parms{device};
      > print "\nCreating $tmp\n";
      > print "mknod ".$tmp." b ".$Parms{Major}." 0\n";
      > @Rslt = split(/ /,`mknod $tmp b $Parms{Major} 0`);
      > if($Debug){
      > print "\n@Rslt\n";}
      >
      > #create /dev/????1
      > $tmp.="1";
      > @Rslt = split(/ /,`mknod $tmp b $Parms{"Major"} 1`);
      > if($Debug){
      > print "\n@Rslt\n";}
      > }
      >
      > sub FormatDsk{
      > @Rslt = split(/ /,`/sbin/sfdisk -g $Parms{"device"}`);
      > print "\n@Rslt\n";
      > print "Cylinders: $Rslt[1]\n";
      >
      > # sfdisk $device << EOF
      > # 0,$cylinders,81
      > # ;
      > # ;
      > # ;
      > # EOF
      >
      >
      > # if( $status == 0) then
      > # printf "\nSeems all OK! - Tout semble OK!\n"
      > # else
      > # printf "\n!!!ERROR: Unable to create
      > partition table. Please make a low level format of flash disk.\n!!!
      > Erreur: Impossible de créer la table des partitions, faites un 'low
      > level format' du disque flash.\n"
      > # exit (1)
      >
      > # endif
      > }
      >
      > -=-=-=-=-=-=-= End of PERL script -=-=-=-=-=-=-=-=
      > -=-=-=-=-=-=-= Start of configuration file 486Core.cfg
      -=-=-=-=-=-=-=
      > #Infos pour créer le "device"
      > #Major provient de la documentation du SBC
      > Major = 254
      > device = /dev/hrfd
      > #device = /dev/hda1
      > cylinders = 963
      > mountpoint = /mnt/flash
      >
      > -=-=-=-=-=-=-=- End of Config file (that MUST be in
      ./config/-=-=-=-=-





      Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    • Eric Thibodeau
      Thanks again for the info...but here is what I am now getting... 1. Each time I run the script, I get useless use of sprintf in void context messages...I
      Message 2 of 4 , Mar 30, 2001
      • 0 Attachment
        Thanks again for the info...but here is what I am now getting...

        1. Each time I run the script, I get "useless use of sprintf in void
        context" messages...I wouldn't usually worry too much about this but my
        sprintf "concatenation" does indeed NOT work! Also weird, I attempt to print
        out the actual string I am sending out to the shell but the printout is
        completely corrupted.

        Line where I attempt to print out the command line passed to the shell:

        print "mknod ".$Prm." b ".$Parms{Major}." 0\n";

        the printout I actually get on my screen is REVERSED...by this I mean I get
        the following:

        0 254/dev/hrfd

        space between the 0 and 254, 254 and /dev/hrfd glued together and mknod
        doesn't eve appear!

        I would have expected the following to be printed out:

        mknod /dev/hrfd b 254 0

        God knows PERL ends up actually executing!

        Anyone ever seen this reversal of stuff in PERL!?!?!?!?!?

        I am attaching the lates script, configuration file (must be in ./config
        folder as before) and a screen capture of my linux console following the
        execution of the script (screen.txt).

        Also note that the device /dev/hrfd exists and unlink does not seem to be
        able to remove it!



        -----Original Message-----
        From: Damien Carbery [mailto:daymobrew@...]
        Sent: Friday, March 30, 2001 12:57 PM
        To: perl-beginner@yahoogroups.com
        Subject: [PBML] Re: Help! (what a classic)...concatenation operator on
        drugz?!?


        I don't know about your concetenation issues but I noticed one small
        thing:

        > print "\n\nRemoving $Prm\n";
        > @Rslt=split(/ /,`rm $Prm`);
        > if($Debug){
        > print "\`rm\` result: @Rslt\n";}
        > }
        I recommend using perl to remove the file instead of invoking an
        external program (time and CPU intensive, even though this is probably
        not an issue here).
        my $UnlinkResult;
        print "\n\nRemoving $Prm\n";
        $UnlinkResult = unlink( $Prm );
        print "unlink result (1 is good): $UnlinkResult\n" if ( $Debug );

        Maybe you could try using sprintf() to concatenate the "1":
        sprintf( $Prn, "%s%s", $Prn, "1" );
        I realise this is not a nice solution.
      • Charles K. Clarkson
        ... __________________________ (install.pl lines 89 and 106) ... The sprintf function returns a value. Use it like: $formatted = sprintf( somepattern ,
        Message 3 of 4 , Mar 30, 2001
        • 0 Attachment
          Eric Thibodeau <rd_lab@...> wrote:
          : Thanks again for the info...but here is what I am now getting...
          :
          : 1. Each time I run the script, I get "useless use of sprintf in void
          : context" messages...I wouldn't usually worry too much about this but
          : my sprintf "concatenation" does indeed NOT work! Also weird, I
          : attempt to print out the actual string I am sending out to the shell but
          : the printout is completely corrupted.

          __________________________

          (install.pl lines 89 and 106)

          : sprintf($Prm,"%s%s",$Prm,"1");
          : sprintf($tmp,"%s%s",$Prm."1");

          The sprintf function returns a value. Use it like:
          $formatted = sprintf('somepattern', variable(s) );

          sprintf($Prm,"%s%s",$Prm,"1") by itself is considered
          void context. Sprintf doesn't do anything in void context.

          If your trying to add a '1' to the end of $prm:

          $prm .= 1;

          If you trying to put a '1' at the end of $prm and assign it
          to $tmp:

          $tmp = "$prm1";

          From the manuual:
          Don't fall into the trap of using a printf when a
          simple print would do. The print is more efficient
          and less error prone.

          :
          : Line where I attempt to print out the command line passed to the shell:
          :
          : print "mknod ".$Prm." b ".$Parms{Major}." 0\n";
          :
          : the printout I actually get on my screen is REVERSED...by this I mean I
          get
          : the following:
          :
          : 0 254/dev/hrfd
          :
          : space between the 0 and 254, 254 and /dev/hrfd glued together and mknod
          : doesn't eve appear!
          :
          : I would have expected the following to be printed out:
          :
          : mknod /dev/hrfd b 254 0
          :

          I got:
          Creating /dev/hrfd
          mknod /dev/hrfd b 254 0

          Looks like you have an operating system error there.

          HTH,
          Charles K. Clarkson


          Real men don't ask for directions.
          Programmers are not real men.
        • Eric Thibodeau
          [-=*Smashes Head on keyboard*=-] [*Grin*] Uhm, the reason I switched to sprintf was following your recomendation since the concatenation screwzz up! When
          Message 4 of 4 , Apr 2, 2001
          • 0 Attachment
            [-=*Smashes Head on keyboard*=-]
            [*Grin*]
            Uhm, the reason I switched to sprintf was following your
            recomendation since the concatenation screwzz up! When trying to use the
            ".=" operator I would end up with screwy results such as follows:


            $tmp="/dev/hrfd";
            $tmp.="1";
            print $tmp; #--> renders: 1dev/hrfd
            print "Removing $tmp"; #--> renders: 1emoving /dev/hrfd

            I somehow beleive this freaky problem to be linked with my inverted
            mknod printout.

            Note on the OS: I tought the same thing as you did when I
            encountered the problem (library screwed up?). I re-installed Linux Mandrake
            (7.1) reformating the root partition. The problem was apparent in Mandrake
            8.0 and is also there in 7.1. This one is really driving me Nukin Futts!

            The worst part of all this is that the script does indeed work on a
            different physical machine (ie: your's and my collegue's). Even weirder, the
            script does NOT work on my machine and DOES NOT work on an NFS mounted
            machine (which should in theory remove the possibility of hardware issues).
            And since I have reinstalled 2 different versions of OS (MDK 8.0-7.1) the
            issue shouldn't be software either.

            hmmmmmmmmm....maybe......yes, Okay, who'se the smart ass that put a
            black hole in my system (would account for the reversed mknod function and
            the 1 printing out at the begining and not the end of a simple print
            function).
            [-=*Okay...too much koffee*=-]

            As you can see, I am somehow desperate to resolve this one. I don't
            think it's anything wrong with the script itself but I would love to get
            pointers as to how I should resolve such a special problem...Any
            library/software expert out there with such debuging experience!?

            Thanks for all replies!

            Sincerely,

            Eric Thibodeau
            (514) 374-6204 x453
            ELECTROLINE R&D

            -----Original Message-----
            From: Charles K. Clarkson [mailto:c_clarkson@...]
            Sent: Friday, March 30, 2001 8:51 PM
            To: perl-beginner@yahoogroups.com
            Subject: Re: [PBML] Re: Help! (what a classic)...concatenation operator
            on drugz?!?


            Eric Thibodeau <rd_lab@...> wrote:
            : Thanks again for the info...but here is what I am now getting...
            :
            : 1. Each time I run the script, I get "useless use of sprintf in void
            : context" messages...I wouldn't usually worry too much about this but
            : my sprintf "concatenation" does indeed NOT work! Also weird, I
            : attempt to print out the actual string I am sending out to the shell but
            : the printout is completely corrupted.

            __________________________

            (install.pl lines 89 and 106)

            : sprintf($Prm,"%s%s",$Prm,"1");
            : sprintf($tmp,"%s%s",$Prm."1");

            The sprintf function returns a value. Use it like:
            $formatted = sprintf('somepattern', variable(s) );

            sprintf($Prm,"%s%s",$Prm,"1") by itself is considered
            void context. Sprintf doesn't do anything in void context.

            If your trying to add a '1' to the end of $prm:

            $prm .= 1;

            If you trying to put a '1' at the end of $prm and assign it
            to $tmp:

            $tmp = "$prm1";

            From the manuual:
            Don't fall into the trap of using a printf when a
            simple print would do. The print is more efficient
            and less error prone.

            :
            : Line where I attempt to print out the command line passed to the shell:
            :
            : print "mknod ".$Prm." b ".$Parms{Major}." 0\n";
            :
            : the printout I actually get on my screen is REVERSED...by this I mean I
            get
            : the following:
            :
            : 0 254/dev/hrfd
            :
            : space between the 0 and 254, 254 and /dev/hrfd glued together and mknod
            : doesn't eve appear!
            :
            : I would have expected the following to be printed out:
            :
            : mknod /dev/hrfd b 254 0
            :

            I got:
            Creating /dev/hrfd
            mknod /dev/hrfd b 254 0

            Looks like you have an operating system error there.

            HTH,
            Charles K. Clarkson


            Real men don't ask for directions.
            Programmers are not real men.







            Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
          Your message has been successfully submitted and would be delivered to recipients shortly.