in reply to substr to split lines?

you need to put a '/s' on those first two regexps to get them to work across multiple lines:

$description =~ s/^(\s+)?$//sg; #get rid of blank lines $description =~ s/\n/ /sg; #get rid of new lines

update:

in addition, changing the $description =~ s/$temp//; to substr($description,0,75) = "" seems to fix it and is probably better form.

anders pearson

Replies are listed 'Best First'.
Re: Re: substr to split lines?
by dvergin (Monsignor) on Aug 28, 2001 at 22:50 UTC
    Oops... No. The regex modifier /s only effects matching of '.' (dot). (And ignores $* -- but don't worry about that.) the_slycer's problem lies elsewhere.
        You were probably thinking of /m.

        I always use them both, anyway.

Re: Re: substr to split lines?
by the_slycer (Chaplain) on Aug 28, 2001 at 23:04 UTC
    I'm not sure how your solution is to work with what I need to do though. (Probably because of my lack of understanding with regards to substr).

    The way the code reads now is:
    $description =~ s/^(\s+)?$//sg; $description =~ s/\n/ /sg; while ($description) { $f_desc .= "T".(substr($description,0,75) = "")."\n"; } print $f_desc;
    However, when given a description like the following (which is what I am working with) it doesn't come out quite right.
    2001/08/28 10:15:54 AM auser 08/28/01 10:15:53 auser PostalCode.24th floor. MachineID, printer keeps jamming (A person' +s Name). Lexmark optra s1250. 2001/08/28 10:17:57 AM auser PostalCode.24th floor. MachineID, printer keeps jamming (A person's N +ame). Lexmark optra s1250.
    The above code makes it read like:
    T floor. MachineID, printer keeps jamming (A person's Name). Lexmark +optra s125 T0. 2001/08/28 10:17:57 AM auser PostalCode.24th floor. MachineID, +printer kee Tps jamming (A person's Name). Lexmark optra s1250. T
    So it looks like I'm missing the first line, and I'm not sure why :-)
    UPDATE: Japhy got it. That's why he's the saint and I'm the lowly whatever I am now :-)