Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

string manipulate

by amoura (Initiate)
on Jun 25, 2002 at 22:29 UTC ( [id://177224]=perlquestion: print w/replies, xml ) Need Help??

amoura has asked for the wisdom of the Perl Monks concerning the following question:

Hello friends , I got this file containing the following:
-D__c_plusplus=1 -D__cplusplus=1 \ -D__NAMESPACES -D__STANDARD_CXX \ -D__ghs -Dghs -D__SoftwareFloat \ -D__m68k -Dm68k -D__mc68000 \ -D__m68ec060 -Dm68ec060
I am trying to match the string with "-D" , I was able to do that fine , however; I get also the "\" that appear at the end of each line . any hint please so I can match my string without geting the "\" at the end of the line ..

thanks much

edited: Wed Jun 26 15:35:45 2002 by jeffa - title spelling correction

Replies are listed 'Best First'.
Re: string minuplate
by gav^ (Curate) on Jun 26, 2002 at 00:34 UTC
    If I understand you correctly, something like this should do the trick:
    my @flags = (); while (<DATA>) { push @flags, /(-D\S+)/g; } use Data::Dump qw(dump); print dump(\@flags); __DATA__ -D__c_plusplus=1 -D__cplusplus=1 \ -D__NAMESPACES -D__STANDARD_CXX \ -D__ghs -Dghs -D__SoftwareFloat \ -D__m68k -Dm68k -D__mc68000 \ -D__m68ec060 -Dm68ec060 __END__ Result: [ "-D__c_plusplus=1", "-D__cplusplus=1", "-D__NAMESPACES", "-D__STANDARD_CXX", "-D__ghs", "-Dghs", "-D__SoftwareFloat", "-D__m68k", "-Dm68k", "-D__mc68000", "-D__m68ec060", "-Dm68ec060", ]
    It would help if your question was a little less vague and you provided some sample output :)

    gav^

      Dear gav^ , here is a sample output :
      -D__PROTOTYPES__ -D__STDC__=0 -D__c_plusplus=1 -D__cplusplus=1 \ -D__LANGUAGE_CXX -D__LANGUAGE_CXX__ -D__NAMESPACES -D__STANDARD_CX +X \ -D__STANDARD_CXX_HEADERS -D__ghs__ -D__ghs -Dghs -D__SoftwareFloat + \ -D__SoftwareDouble -D__COFF -D__m68k__ -D__m68k -Dm68k -D__mc68000 + \ -Dmc68000 -D__MC68000 -DMC68000 -D__motcoff -D__m68ec060 -Dm68ec06 +0 \ -D__ghs_alignment=4 -D__BigEndian -DBigEndian -D__DOUBLE_HL \ -D__IeeeFloat -DIeeeFloat -D__Ptr_Is_Signed__ -D__Char_Is_Signed__ + \ -D__SIGNED_CHARS__ -D__WChar_Is_Signed__ -D__WChar_Is_Long__ \ -D__Int_Is_32 -D__Long_Is_32 -D__Ptr_Is_32 -D__Reg_Is_32 \ -DSEL_AIS_TARGET -DAIS_BUILD -DINCLUDE_XDM_SWERR -DXDM_ON \ -DXDM_DIRECT -DXDM_SYNC -DTARGET_PROTO \ -DACN_SUPPORTS_SIGNALING_SERVICES -DGH_DEBUG \ -DACN_SUPPORTS_TRAFFIC_SERVICES -DPIMTUNE_ACN_APP -DNOIS_USES_CCLH +C \ -DACL_SUPPORTS_STREAMS -DPIM_PFB -DESELVER_NTGB06CA -DSELREV_X2 \ -DTARGET_ESEL -DLOG_VOCODER_STATS -DOFP_SUPPORTED -DDEBUG \ -DSRM_DEBUG_TURN_ON -D_GH -DTARGET_060 -DMEMMONITOR \
      It looks bad sorry, but do you know of any other way , I can get rid of the "\" at the end of each line without using Data:Dump thanks much

      Edit: Added <code> tags. larsen

Re: string minuplate
by bronto (Priest) on Jun 26, 2002 at 08:24 UTC

    This will read from a FILE filehandle and put the -D chunks in an array. I hope you could adapt it to fit your needs

    my @Ds ; while (<FILE>) { my @matches = /(-D\S*)/g and push @Ds,@matches ; }

    Ciao!
    --bronto

    # Another Perl edition of a song:
    # The End, by The Beatles
    END {
      $you->take($love) eq $you->made($love) ;
    }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-24 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found