#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    31
    Rep Power
    2

    Printing hex value from CSV file.


    Hi All,

    I have one csv file (prac.csv):
    (Which has hexadecimal numbers init)
    a,b,,,
    c,x,,,
    e,r,0x0,,
    ,,0x10,u,
    q,w,0x0,u,
    #####################################################
    Now i wan to take input of prac.csv
    and wan to print its hexadecimal value....

    i.e.
    In first line hex value=,
    In second line hex value=,
    In third line hex value=0x0,
    In fourth line hex value=0x10,
    In fifth line hex value=0x0,

    ####################################################3

    Can you please help me???
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    830
    Rep Power
    496
    Use a simple regex to pick up the string representing hexadecimal values.

    For example, something like this:

    Perl Code:
    while (my $line = <>) {
         my $hex_value = $1 if $line =~ /(0x[\dabcdef]+)/i;
         print "In line $., hex value = $hex_value\n";
    }


    That is assuming that you have only one hex value per line. But it is easy to change it to an array of hex values if you may have several.
    Last edited by Laurent_R; April 15th, 2013 at 01:48 PM. Reason: Corrected typo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    31
    Rep Power
    2
    Originally Posted by Laurent_R
    Use a simple regex to pick up the string representing hexadecimal values.

    For example, something like this:

    Perl Code:
    while (my $line = <>) {
         my $hex_value = $1 if $line =~ /(0x[\dabcdef]+)/i;
         print "In line $., hex value = $hex_value\n";
    }


    That is assuming that you have only one hex value per line. But it is easy to change it to an array of hex values if you may have several.
    Okay I got the idea. Thanks Laurent_R, you have saved me again.

IMN logo majestic logo threadwatch logo seochat tools logo