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

I Have A HUGE list of words and definitions on the same line and i want to add a new line to so that the definitions are on a different line than the words can someone help me with this

Replies are listed 'Best First'.
Re: adding a return to a file
by moritz (Cardinal) on May 17, 2012 at 12:26 UTC

    Read perlintro. Start to learn to program. Write a program that solves your problem.

    Since you didn't provide any sample input and output, and haven't shown us what you have tried and where you problems are, that seems to be the best advice we can give you at the moment.

Re: adding a return to a file
by roboticus (Chancellor) on May 17, 2012 at 12:29 UTC

    AlexanderTheGreat:

    What part gives you trouble? If it's opening and reading the file, try reading perldoc -f open. It shows how to open the file, and a few paragraphs down gives an example skeleton of a program that opens a file and processes it line by line.

    If you're having trouble with splitting up the line, you might try reading perldoc -f split to see how to use split to break the line apart. If the definition is always the first word in each line, you can use a regular expression like:

    if (/^\s*(\w+)(.*)/) { my ($word, $definition) = ($1, $2); ... }

    Perl has *plenty* of documentation on working with regular expressions, such as:

    There's more out there, as well.

    If you're very new to perl, be sure to read perldoc perlintro to get a basic overview. In fact, if you read through perlintro, you'll probably have enough information to get through it.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: adding a return to a file
by ww (Archbishop) on May 17, 2012 at 13:20 UTC

      My Actual Question(Sorry I Didnt put this in the first time) Was I Have a list of words and definitions

      ex

      accession n. Induction or elevation, as to dignity, office, or government. and i want it to look like this

      accession

      n. Induction or elevation, as to dignity, office, or government.

      and then i want to turn it into a hash because i am making a dictionary

        I am going to add my code so you guys can take a look at what i have so far

        #! /usr/bin/perl use warnings; use strict; #opening the file that i am reading from open TEST, 'test.txt' or die $!; #saving the file as a hash my %test = <TEST>; #looping through the hash and printing out all the words # i am going to eventualy have the person enter a sylable to look up r +hyming words for (keys %test) { print "$_"; } # and then give the definition of the word that you type in print " Please Enter A Word "; my $choice = <STDIN>; #the vaariable to check if the word is in the file my $word = 10; for (keys %test) { #if it is print out the definition (the hash value) if ($choice eq $_) { print $test{$_}; $word = 1; } } close TEST; #if it is not then say sorry word not found and ask them to retype it +and a definition if ($word != 1) { open TEST, '>>test.txt' or die $!; print "Sorry Word Not Found\n"; print "Please Re-enter Word\n"; my $input = <STDIN>; print "Please Enter Definition\n "; my $def = <STDIN>; #append the word to the file print TEST "\n",$input; print TEST $def; }

        That's not a question.

        Looks a bit like a task description, but what's the pay?