Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backwards logic in perluniintro (5.10.0) #9457

Closed
p5pRT opened this issue Aug 21, 2008 · 5 comments
Closed

backwards logic in perluniintro (5.10.0) #9457

p5pRT opened this issue Aug 21, 2008 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 21, 2008

Migrated from rt.perl.org#58218 (status was 'resolved')

Searchable as RT58218$

@p5pRT
Copy link
Author

p5pRT commented Aug 21, 2008

From bmb@Mail.Libs.UGA.EDU

-- Perl 5.10.0 documentation --
http​://perldoc.perl.org/perluniintro.html#Questions-With-Answers

How Do I Detect Data That's Not Valid In a Particular Encoding?

Use the Encode package to try converting it. For example,

  use Encode 'decode_utf8';
  eval { decode_utf8($string, Encode​::FB_CROAK) };
  if ($@​) {
  # $string is valid utf8
  } else {
  # $string is not valid utf8
  }

Should be

  use Encode 'decode_utf8';
  eval { decode_utf8($string, Encode​::FB_CROAK) };
  if ($@​) {
  # $string is not valid utf8
  } else {
  # $string is valid utf8
  }

@p5pRT
Copy link
Author

p5pRT commented Aug 23, 2008

From @druud62

Brad Baxter schreef​:

# New Ticket Created by Brad Baxter
# Please include the string​: [perl #58218]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=58218 >

-- Perl 5.10.0 documentation --
http​://perldoc.perl.org/perluniintro.html#Questions-With-Answers

How Do I Detect Data That's Not Valid In a Particular Encoding?

Use the Encode package to try converting it. For example,

use Encode 'decode\_utf8';
eval \{ decode\_utf8\($string\, Encode&#8203;::FB\_CROAK\) \};
if \($@&#8203;\) \{
    \# $string is valid utf8
\} else \{
    \# $string is not valid utf8
\}

Should be

use Encode 'decode\_utf8';
eval \{ decode\_utf8\($string\, Encode&#8203;::FB\_CROAK\) \};
if \($@&#8203;\) \{
    \# $string is not valid utf8
\} else \{
    \# $string is valid utf8
\}

Alternative-1​:

  use Encode 'decode_utf8';
  if ( eval {
  decode_utf8($string, Encode​::FB_CROAK);
  1;
  }
  )
  # $string is valid utf8
  } else {
  # $string is not valid utf8
  }

Alternative-2​:

  use Encode 'decode_utf8';
  eval {
  decode_utf8($string, Encode​::FB_CROAK);
  1;
  }
  or do {
  # $string is not valid utf8
  };

--
Affijn, Ruud

"Gewoon is een tijger."

@p5pRT
Copy link
Author

p5pRT commented Aug 23, 2008

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 24, 2008

From @rgs

2008/8/23 Dr.Ruud <rvtol+news@​isolution.nl>​:

http​://perldoc.perl.org/perluniintro.html#Questions-With-Answers

How Do I Detect Data That's Not Valid In a Particular Encoding?

Use the Encode package to try converting it. For example,

use Encode 'decode\_utf8';
eval \{ decode\_utf8\($string\, Encode&#8203;::FB\_CROAK\) \};
if \($@&#8203;\) \{
    \# $string is valid utf8
\} else \{
    \# $string is not valid utf8
\}

Should be

use Encode 'decode\_utf8';
eval \{ decode\_utf8\($string\, Encode&#8203;::FB\_CROAK\) \};
if \($@&#8203;\) \{
    \# $string is not valid utf8
\} else \{
    \# $string is valid utf8
\}

Alternative-1​:

use Encode 'decode\_utf8';
if \( eval \{
       decode\_utf8\($string\, Encode&#8203;::FB\_CROAK\);
       1;
     \}
   \)
    \# $string is valid utf8
\} else \{
    \# $string is not valid utf8
\}

I chose that one. Thanks, applied as #34223.

@p5pRT
Copy link
Author

p5pRT commented Aug 24, 2008

@rgs - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant