Re: split, no repeat- Regular expression



Nina <tin_tint@xxxxxxxxxxx> wrote:


> what's the problem with this script?
>
> #!usr/bin/perl -w


You are missing a slash character there.

Please post _actual_ code!


> open (FILE, "$file") or die "Cannot open file.\n";


You should include the $! variable in your die() message.

You should not have quotes around a lone variable:

perldoc -q vars

What's wrong with always quoting "$vars"?


> foreach (@file) {s/\s+/\t+/g;}


That replaces _runs_ of whitespace characters (any of: line feed,
carriage return, tab, formfeed, space) with a tab and a plus sign.

The 2nd part of s/// is a *string*, not a regular expression.

To TRansliterate space characters to tab characters:

tr/ /\t/;


--
Tad McClellan SGML consulting
tadmc@xxxxxxxxxxxxxx Perl programming
Fort Worth, Texas
.



Relevant Pages

  • Re: Great SWT Program
    ... Vim -- car is fixed, ... and/or press tab again to get a list of choices. ... to type one or more additional characters and press tab again. ...
    (comp.lang.java.programmer)
  • Re: Decatenate a field with Make Table Query?
    ... You can probably do something similar in MS Word, lining them up using tab characters in ordinary paragraphs. ... You can use Word to delete lines that contain only white space, and you can delete repeated paragraph marks. ... I would define a special paragraph style that would include the tab settings for this operation, but would not save it in the global Word template, as you'll likely never need this style again, so leave "Add to Template" unchecked, but check "Automatically Update". ... In the Excel cell the paragraph marks show up as bangs; ...
    (microsoft.public.access.queries)
  • Re: Tabs vs. Spaces
    ... all displays were fixed character width. ... to align properly is if my display has the same tab spacing as yours. ... every 4 characters -- some oddballs even used three or five. ...
    (alt.comp.lang.learn.c-cpp)
  • Auto Tab
    ... automatic tab occurs when the last character permitted by ... The AutoTab property uses the following settings. ... You create an input mask for a control by using the ... of characters for each record. ...
    (microsoft.public.access.forms)
  • Re: Tab delimiter
    ... records in a line sequential file are delimited by delimiters. ... can contain only printable characters and record delimiters. ... "If there are tab characters in an input record, ... align the following characters to preset tab positions. ...
    (comp.lang.cobol)