Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Trying to capture Alt characer in Perl

by sanPerl (Friar)
on May 19, 2014 at 08:10 UTC ( #1086600=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,

I am using use Spreadsheet::XLSX. I am trying to capture character "Alt+Enter" in CSV file and trying to convert it to space

$mycell_value = $excel_sheet_cell -> {Val}; $mycell_value=~ s/\n+/ /gs;
where $excel_sheet_cell -> {Val} contains value in cell. This is still Not working. THe CSV file , if it is opened in Excel, it still shows Newlines in cell. Can someone kindly help.

Update: I am using $mycell_value variable to output in CSV (and Not $excel_sheet_cell -> {Val})

I guess some monks have mis-understood the question. They have interpreted that I want to put Alt+Enter character in CSV. But the requirement is reverse.

I already have an Excel file (as input) which contains a cell having Enter character. This character is entered by some user, using 'Alt+Enter' key combination. Now I want to convert this Enter character (or 'Alt+Enter' char) to space. This is what is Not happening and I am getting CSV file with Enter character (which is spoiling structure of CSV). Thank, SanPerl

Replies are listed 'Best First'.
Re: Trying to capture Alt characer in Perl
by Corion (Pope) on May 19, 2014 at 08:19 UTC

    Have you inspected what bytes are in that cell?

    $Data::Dumper::Useqq= 1; print Dumper $mycell_value;

    Most likely, the character is not \n but \r\n or something like it.

Re: Trying to capture Alt characer in Perl
by Bloodnok (Vicar) on May 19, 2014 at 10:34 UTC
    Strictly speaking, there is no <Alt> character per se, the <Alt> and indeed <Ctrl>, keys are modifiers in as much as the actual character typed is modified to a different ASCII value, so you should refer to the wisdom forwarded by other monks WRT establishing the actual data values that the <Alt> & <Ctrl> keys generate.

    A user level that continues to overstate my experience :-))
Re: Trying to capture Alt characer in Perl
by Anonymous Monk on May 19, 2014 at 08:16 UTC

    What is "alt+Enter" character?

    use  Data::Dump::dd( $mystery_data ) to find out, then with appropriate quotemeta s///ubstitute it

      Thanks dear monk, alt+enter is a key combination which any user can use and add a 'newline' in Excel cell.
Re: Trying to capture Alt characer in Perl
by hdb (Monsignor) on May 19, 2014 at 08:41 UTC

    In the two lines you show us, you do not modify the cell at all. You read the value from the cell, you modify that value, but nowhere you put it back into the cell. Can you show that line as well please?

Re: Trying to capture Alt characer in Perl
by leuchuk (Novice) on May 20, 2014 at 13:51 UTC
    Do I understand it right? You want to output somehow that alt+enter in a CSV file? Somehow having a line break in an Excel cell, don't you? If my assumption is correct the answer is simple: It's not possible. CSV doesn't allow any formatting. An "enter" will destroy the structure of a CSV file because Enter is the symbol for line end. If you want to have the cell format you should output some sort of Excel format, preferrably XLSX.
      That is not true. You can have newlines in strings in CSV if the strings are properly quoted.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      No , I already have an Excel file (as input) which contains a cell having Enter character. This character is entered by some user, using 'Alt+Enter' key combination. Now I want to convert this Enter character (or 'Alt+Enter' char) to space. This is what is Not happening and I am getting CSV file with Enter character retained (which is spoiling structure of CSV).

      BTW, thanks a lot for your interest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1086600]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-10-25 19:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?