PERL, split and Outcoded's nightmare
Results 1 to 7 of 7

Thread: PERL, split and Outcoded's nightmare

  1. #1
    Senior Member - 1000+ Club Outcoded's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere in the UK, never quite sure where
    Posts
    1,689

    Red face PERL, split and Outcoded's nightmare

    This should be an easy question... at least that's what we thought.

    Does anyone know a way to feed a string into an array such that every character is a separate item? (Kinda like a string tokeniser if you see what I mean).

    Thanks in advance, this one's driving me nuts.

  2. #2
    Senior Member - 1000+ Club Outcoded's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere in the UK, never quite sure where
    Posts
    1,689

    Post

    OK... it's still driving me nuts.

    Help. Please.

  3. #3
    Registered User Deity's Avatar
    Join Date
    Mar 2001
    Location
    Elsewhere
    Posts
    1,412

    Post

    I know how to do this in C++ but not in Perl. Sorry.

  4. #4
    Registered User LTB_Dagger_Qc's Avatar
    Join Date
    Mar 2002
    Location
    Montreal, Qc, Canada
    Posts
    89

    Post

    youd have to make a search of your string caracter per caracter but at first glance(i'll look it up further) you'd need a variable for each caracter of your string, you'd need to now or predict how many caracters you have in your srting. Like an automatic variable creator depending on the amount of caracters your string has.. Could be long and messy getting each and every caracter after that process.

    I'll check if there is a function or anything that would ease the process. I'll even ask my teacher.. lol

  5. #5
    Senior Member - 1000+ Club Outcoded's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere in the UK, never quite sure where
    Posts
    1,689

    Post

    Thanks for that, I'm reading in an ASCII file so the file size should equal the number of characters right?

    Deity. I do some C++, so maybe if you can do it in base concepts (as opposed to a straight string buffer like I would in Java), that could help me get a feel of what's going on.

    I've emailed one of my lecturers, who's an expert in PERL, but I'm waiting on an answer.

    Thanks for all the help folks, this one's still taxing me

  6. #6
    Registered User Deity's Avatar
    Join Date
    Mar 2001
    Location
    Elsewhere
    Posts
    1,412

    Post

    Disclaimer to all coding gurus: I am by no means a C/C++ expert. If I make any obvious mistakes or errors, please point them out...nicely.

    Well, C++ has two different styles of strings. There is the newer string class and the old character array (c.string). What you are talking about sounds like a conversion from the new class to the old. The c strings would assign a seperate element in a character array to each character in the string, and then termintate it with a NULL character. For example:
    [code] char myChar[255]; </pre><hr></blockquote> would declare a c string with 255 elements. C++ has a conversion function built in called c_str(), which changes a typical string into a character string.

    I can imagine other, less clean ways of accomplishing the same thing. If you setup a character array, and pulled a single character substring out of the original string then incrementally stored that value into the character array. Again, terminate the character array with a NULL value.

    Hope this helps.
    A bored admin is a very dangerous person...

  7. #7
    Senior Member - 1000+ Club Outcoded's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere in the UK, never quite sure where
    Posts
    1,689

    Post

    Thanks, that's got me thinking.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •